#SyncVar doesn't wait for value to be spawned in on the client if it's a network object. Workaround?
20 messages · Page 1 of 1 (latest)
It's a race condition, which is why we tell you in the docs to avoid NI/NB/GO in SyncVar / Sync* collections / ClientRpc. The client may not have the referenced object for various reasons
Well I solved my problem by just not using SyncVar, but I wonder, could I modify the default behaviour of SyncVar so that it syncs only when a client is spawned in & ready instead of immediately?
I mean modifying Mirror's code?
It's not as simple as you think...we have a WIP to make this more robust, but our first run at it fails when there are lots of objects
Ideally I'd just delay the execution of SyncVar when someone latejoins
It's really not a common case where you need to SyncVar NI/NB/GO...there's almost always a smarter way to do things server side
What does NI/NB/GO refer to?
Ah
NetworkIdentity / NetworkBehaviour / GameObject (with NI on it)
What are you really attempting to do...context matters in giving suggestions of better approaches
I just have one question, how can I use the weaver myself, manually? (if I'm not misunderstanding what the weaver even is)
Like not passing anything through rpcs, say I just want to serialize or deserialize something the same way Mirror does it with rpcs. How can I access that functionality?
Weaver is pre-build code generation, so you can't access it directly. You can do Network Messages, and you can do custom serialization, but none of this is a good idea. It will be a lot of work for no real gain.
In the example of Cmd/Rpc, weaver generates extra methods that create and send messages, and read and handle messages, respectively.
It would be inefficient to serialize the things I want into Yaml format and then pass that string in an rpc right?
If you make a mono build, you can decompile a network behavior class and see what it generates
very inefficient...awful really
🙂
So I'm imagining byte array would be more efficient?
I'm thinking about creating a custom attribute and then I look at a class and read the values of the fields with that attribute in order, put everything into a byte array and send that through an RPC maybe? And then write them in the same order on the receiving end. And for NI/NB/GO's, I just send their NetIDs instead
If I can do this then I've basically got my own SyncVar, so I can do the syncing when a latejoining client is actually ready rather than immediately
Would seem to be easier to just start a coroutine from the SyncVar hook that waits for time or checks for other things to exist.
e.g. in the hook of a syncvar of the netId, check NetworkClient.spawned if it has the key, if it does, act on it, otherwise start a coroutine that yields until the key is there before acting on it