Closed PolSpock closed 8 months ago
Because you're adding a component in OnStart
, that component won't be serialized across the network because it will essentially be created and added to the GameObject after NetworkSpawn()
is called. You should make sure that any components you want serialized with the GameObject when networked are added before NetworkSpawn()
is called.
In the future we'll look into networking when components are added or removed from a networked GameObject.
Because you're adding a component in
OnStart
, that component won't be serialized across the network because it will essentially be created and added to the GameObject afterNetworkSpawn()
is called. You should make sure that any components you want serialized with the GameObject when networked are added beforeNetworkSpawn()
is called.In the future we'll look into networking when components are added or removed from a networked GameObject.
Yeah by continuing my investigation, this is something i finished to guess.
I was used to switching my PlayerController state from FPSController to SpectatorController by Components.Create
or Component.Destroy
these Components, creating several sync issues.
So by, your message, this is not good logic anymore and i will edit it.
In the mean time, just to satisfy my theory, try doing Components.Create
This is a valid bug report, it's just that it will be resolved at a later date when we add networking of components added or removed after the initial serialization of the GameObject.
There is no issue on OnAwake()
and Components.Create<TestVelocity>();
This is something i just discovered at the same time you posted your first comment
I have already edited my issue with this information (i have edited a lot my issue lol)
We don't support dynamic component adding yet
Describe the bug
Hi,
It was a nightmare to get precisely what was the issue, but here is it.
When you have a Component with
[Sync]
properties who has been dynamically added after aGameObject.OnAwake()
, the properties are not synced between players. So basicallyGameObject.OnStart()
orGameObject.OnEnabled()
.So typically
Components.Create<CharacterController>();
has SyncVelocity
but will never be synced between players instead you create a hotload.This is the same for all Components i've added dynamically after a
GameObject.OnAwake()
who contain[Sync]
values. (Example throughGameObject.OnStart()
)To Reproduce
Let's start the reproduction steps : 1) Download https://github.com/Facepunch/sbox-scenestaging/issues 2) Open
networking.scene
3) CreateTestVelocity.cs
Component with:4) Next, go to
NetworkTest.cs
Add this part
OnStart()
method :Edit the
OnUpdate()
method with my shit logs :5) Start
networking.scene
, and connect the secondary user. 6) Move around and look at the console logs: the FdpVelocity [Sync] is not Synced between players 7) Hotload the game and magically players are resyncedExpected behavior
[Sync]
from Component who has been dynamically added must be synced between players (without hotload too)Media/Files
My reproduce steps in video:
https://github.com/Facepunch/sbox-issues/assets/5229571/9af2f56e-927a-404b-a7e3-4d15e853d899
Additional context
No response