Initialize database after Runner.Spawn

Options
Elen
Elen
edited April 2022 in Fusion

I used the host-client mode.

I want to initialize data using index after spawn

Currently, table indexes are initialized using RPC, but sometimes they are not initialized on the local client. Perhaps it is a problem that the arrival order is changed because the speed of the router that is transmitted using RPC after spawning is different.

In the Spawned callback function, we tried to send a packet to the server to request initialization parameters, but we could not specify this object because DynamicWordCount is nullptr.

And since it was impossible to convert between bytes of NetworkedID, it was not possible to specify an object by NetworkID

I want to know if there is a safer way to initialize a table

Answers

  • ramonmelo
    Options

    Hi @Elen ,


    Can you describe what are you really trying to accomplish?

    Unfortunately, I don't quite understand what is the goal of this implementation.


    A few points to keep in mind:

    1. Only the Server in the ClientServer mode is able to update the NetworkObject state, and it is replicated over the network.
    2. The Client can change the Network Properties (State), but those are not replicated.
    3. If you want the State of a NetworkObject to be initialized before being sent to the Clients, you can use the OnBeforeSpawned method on the Server, in order to do this. (https://doc-api.photonengine.com/en/fusion/current/class_fusion_1_1_network_runner.html#ad410b70aa16fc2123bfc58d713c42c2b) when invoking the Spawn method.

    --

    Ramon Melo

    Photon Fusion Team

  • Elen
    Options

    Firstable im sorry for having you a bit of misunderstanding, the point I wanted to ask about was

    'is there any accessible variable that all of clients have commonly that could specify a network object?'

  • ramonmelo
    Options

    Hi @Elen ,


    'is there any accessible variable that all of clients have commonly that could specify a network object?'

    Sure, it is absolutely possible, every NetworkProperty on any NetworkObject can be read by any of the clients connected to the Game Session.

    And yes, you should be able to define a property like this:

    public class PlayerController : NetworkBehaviour {
    
      [Networked] public NetworkObject Target { get; set; }
    
      // ...
    }
    

    In which, Target could point to any other NetworkObject in the game.

    On the client, you can either check this property or use the OnChanged callback to react when it chances in runtime. You can read more about it here: https://doc.photonengine.com/en-us/fusion/current/manual/network-object#react_to_onchanged

    Now, if you are talking about like a Global State that doesn't belong to any particular Client, then this can be done by just spawning a particular NetworkObject only on the Server, and this one will hold all global states of the game, for example. Other clients will be able to read its information as usual.


    --

    Ramon Melo

    Photon Fusion Team

  • Elen
    Options

    thank you i will try.