Events fire prior to scene load?

Hey guys, Making an async game that is working great.

It's a turn based dice game. But i am having trouble with events firing too early.

When i join/rejoin or create a game, I load the scene one the OperationResponse with OperationCode.JoinGame/CreateGame which is the first instance that i know a room was found.

I thought this would be the best way, But it seems at the point after the scene loads but too early for the gameobjects to finish populating that the events fire and the notification i am trying to run gets null references from the scene.

Is there any way to tell photon to runs these events after the scene loads? From what I have heard PUN does this automatically, but i am using the SDK.

To get around this, I have instead saved the event on the room cache and check for it on scene load and perform the action then. Which works fine, But seems kinda clunky to be saving things to the room cache and not using these events at all.

Since its only a basic 2 player game where bets are sent back and forth and i can easily check for certain statuses on refresh is this kinda thing ok? Or am i doing this all wrong? It was quite tough to decipher all this from the memory game demo.

Thanks for any input.

Comments

  • Hi @Crumble,

    Thank you for choosing Photon!

    So you are using Photon Realtime Unity SDK to make an "asynchronous" turn-based dice game. Glad to hear it's working great.

    What events are incoming during scene switch? Could you post some information about the null reference exceptions you are getting?

    Please try moving scene loading calls from OnOperationResponse to OnEvent when you receive the join event of local player (unless you use roomOptions.SuppressRoomEvents = true).
    public override void OnEvent(EventData photonEvent)
        {
            switch (photonEvent.Code)
            {
                case EventCode.Join:
                    if (LocalPlayer.ID == (int)photonEvent[ParameterCode.ActorNr])
                    {
                        // local player entered a room, load new scene                
                    }
    
                    break;
            }
        }
    Also maybe some components need to be attached to a GameObject where the root GameObject in the scene hierarchy has DontDestroyOnLoad which should preserve those GameObjects across scenes.
Sign In or Register to comment.