Convert from ExitGames::Common::Object to float*

I am using unreal engine with photon realtime c++ sdk. I am using opraiseEvent function to send an array of data to other clients. The data is arriving at customEventAction in the form of ExitGames::Common::Object type. How to convert it back to float* or array of floats.

Comments

  • Kaiserludi
    Kaiserludi admin
    edited March 23

    Hi @Rox.


    If you need a copy of the array:

    float* ary = ExitGames::Common::ValueObject<float*>(eventContent).getDataCopy();
    short aryLength = *(ExitGames::Common::ValueObject<float*>(eventContent)).getSizes();
    // some code that uses the array
    ExitGames::Common::MemoryManagement::deallocateArray(ary); // important: deallocate your array copy, once you don't need it any longer - otherwise the memory will be leaked
    


    If you don't need a copy of the array, but only a pointer to the payload of the object:

    float** pAry = static_cast<ExitGames::Common::ValueObject<float*>&>((eventContent)).getDataAddress();
    short aryLength = *static_cast<ExitGames::Common::ValueObject<float*> 
    // important: don't access pAry beyond the lifetime of eventContent, as it only points to member data of eventContent
    


    In general I would like to recommend having a look at CPhotonLib::sendData() and Listener::customEventAction() in demo_typeSupport inside the Client SDKs 'Demos' folder, which focuses on sending and receiving all kinds of different data.