-
Notifications
You must be signed in to change notification settings - Fork 449
How to disable "NetworkVariable is written to, but doesn't know its NetworkBehaviour yet" LogWarning? #2561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@andreyshade As an example:
The first approach (SomeNetworkVariable), the value is set when it is instantiated on all instances (clients or server). Let me know if this helps you with the issue you are experiencing? |
Glad this can be worked around but it adds unnecessary overhead to a component and complicates the Spawn/Init process by having to have more code. I would expect setting initial NetworkVariables from outside the component to be a common use-case. I frequently see user questions asking how to initialize NetworkVariable with a value, respectively wondering why the initial value is 0. I would expect to be able to do the following without raising a warning, in line with my feature suggestions to add a pre-spawn callback to InstantiateAndSpawn: Server:
To write the above without causing the warning, component T would need to have an additional temporary value property that holds the value so it can be assigned to the NetworkVariable in the component's OnNetworkSpawn by the server - which compared to the code above adds unnecessary complexity. Overall working around this warning complicates the code, adds more chance for creating initialization bugs, and adds memory overhead to affected components due to temporary value fields. Alternatively the OnNetworkSpawn could look up the initial value elsewhere, but this may add undesirable coupling and may simply shift the complexity elsewhere. |
This has been something we are looking into fixing.
Then your code to spawn would look like this:
Where there are two options currently to apply a value prior to spawning:
Taking your expected behavior usage pattern, it would look like this with the above approach:
I think the approach you might be looking for would be more like:
|
Thanks for the detailed explanation! Works perfectly! |
Hi Noel! how are you?
i read somewhere that networkbehaviours cannot be added during runtime, and while we are not specifically adding NB during runtime, maybe importing them and their network objects/prefabs from a mod is a similar case? |
@Nikmazza |
I might be late but when you try to define variable on OnNetworkSpawn like;
it can cause this issue. Try this instead:
It might be because when object is initialized that syncronized variable is created again. so it becomes de-synced. |
Closing this issue as a duplicate of #2279 |
I'm using NetworkVariables for configuring some NetworkObjects before spawning and a lot of LogWarnings:
NetworkVariable is written to, but doesn't know its NetworkBehaviour yet. Are you modifying a NetworkVariable before the NetworkObject is spawned?
in my game server logs.
I tried to set log level in the NetworkManager component to error level but it didn't help me and warnings still appear in the logs.

The text was updated successfully, but these errors were encountered: