Initialize database after Runner.Spawn
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on Fusion.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Initialize database after Runner.Spawn
Elen
2022-04-01 08:25:26
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
Comments
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:
Only the Server in the ClientServer mode is able to update the NetworkObject state, and it is replicated over the network.
The Client can change the Network Properties (State), but those are not replicated.
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
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?'
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
thank you i will try.
Back to top