Event Codes //C++ Native

Hey everyone!
For the native C++ photon engine when you call opRaiseEvent(stuff..) for the "event code" is there a reserved codes? I would like to send custom messages with unique event codes.


  • Hi @ChrisB.

    The codes 201-255 are reserved for Photons internal usage.
    The codes 0-200 can be used by the user code for custom events.
    Our recommendation is to just start with code 0 and to count up from there.
  • ChrisBChrisB
    edited February 2020
    @Kaiserludi thank you!
    If you have a moment I'd like to ask you if you have a most efficient way to pass custom packets.
    Right now I have a "NetCore" full of custom structs and when I send the information I just memcpy into an array of bytes then send it. then vice versa for reading.

    Do you know of anything more efficient with the API and custom structs?
  • KaiserludiKaiserludi admin
    edited February 2020
    Hi @ChrisB.

    You could let your custom structs inherit from ExitGames::Common::CustomType<typeCode> so that you can pass the custom struct itself to opRaiseEvent() to avoid the additional copy into / out of the byte array.

    For more information on the custom type APIs please see the API reference for CustomType at https://doc-api.photonengine.com/en/cpp/current/a04866.html, for CustomTypeBase at https://doc-api.photonengine.com/en/cpp/current/a04870.html and for CustomTypeFactory at https://doc-api.photonengine.com/en/cpp/current/a04874.html.

    pathToPhotonClientSDK\Demos\demo_typeSupport contains the class SampleCustomType as an example implementation of a custom type.

    Another approach would be a union:
    struct CustomStruct
    	int member1;
    	short member2;
    	long long member3;
    union CustomUnion
    	CustomStruct type;
    	unsigned char arr[sizeof(CustomStruct)];
    	CustomUnion u;
    	u.type.member1 = 1;
    	u.type.member2 = 2;
    	u.type.member3 = 3;
    	mClient.opRaiseEvent(reliabilityFlag, u.arr, sizeof(u.arr), eventCode);
Sign In or Register to comment.