Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k
stars
435
forks
source link
Only first NetworkTransform synchs when having multiple nested NetworkTransforms on NetworkObject #3002
I have a player object as well as some multiple network object, that rely on having multiple nested network transforms. A network object can look like this:
NetworkObject
Nested NetworkTransform1
Nested NetworkTransform2
When spawning it either as player object as well as normal network object, only the very first NetworkTransform (in my case NetworkTransform1) gets synchronized between every client. When i change the hierarchy to this below, then NetworkTransform2 gets synched.
NetworkObject
Nested NetworkTransform2
Nested NetworkTransform1
Reproduce Steps
Create a NetworkObject with at least 2 nested NetworkTransforms
Start 2 instances of the application (Server and client)
Join the same session
Spawn this NetworkObject
Move both objects with a NetworkTransform component on it to another location
Actual Outcome
As owner of the object, both objects move accordingly. As not owner of the objects, only the first NetworkTransform in the hierarchy moves. The other NetworkTransform stays in the place where it has been spawned.
Expected Outcome
Both NetworkTransforms move and synch over all clients.
Environment
OS: Windows11
Unity Version: 6000.0.13f
Netcode Version: 2.0.0-pre.3
Additional Context
I also recognized during debugging, that NetworkObject.NetworkTransforms is null. I dont know why this happens, but i found that if (type.IsInstanceOfType(typeof(NetworkTransform)) || type.IsSubclassOf(typeof(NetworkTransform))) is always false, even when the type is NetworkTransform.
CodeSnipped from NetworkObject class
m_ChildNetworkBehaviours = new List<NetworkBehaviour>();
var networkBehaviours = GetComponentsInChildren<NetworkBehaviour>(true);
for (int i = 0; i < networkBehaviours.Length; i++)
{
if (networkBehaviours[i].NetworkObject == this)
{
m_ChildNetworkBehaviours.Add(networkBehaviours[i]);
var type = networkBehaviours[i].GetType();
if (type.IsInstanceOfType(typeof(NetworkTransform)) || type.IsSubclassOf(typeof(NetworkTransform)))
{
if (NetworkTransforms == null)
{
NetworkTransforms = new List<NetworkTransform>();
}
NetworkTransforms.Add(networkBehaviours[i] as NetworkTransform);
}
#if COM_UNITY_MODULES_PHYSICS
else if (type.IsSubclassOf(typeof(NetworkRigidbodyBase)))
{
if (NetworkRigidbodies == null)
{
NetworkRigidbodies = new List<NetworkRigidbodyBase>();
}
NetworkRigidbodies.Add(networkBehaviours[i] as NetworkRigidbodyBase);
}
#endif
}
}
Description
I have a player object as well as some multiple network object, that rely on having multiple nested network transforms. A network object can look like this:
When spawning it either as player object as well as normal network object, only the very first NetworkTransform (in my case NetworkTransform1) gets synchronized between every client. When i change the hierarchy to this below, then NetworkTransform2 gets synched.
Reproduce Steps
Actual Outcome
As owner of the object, both objects move accordingly. As not owner of the objects, only the first NetworkTransform in the hierarchy moves. The other NetworkTransform stays in the place where it has been spawned.
Expected Outcome
Both NetworkTransforms move and synch over all clients.
Environment
Additional Context
I also recognized during debugging, that NetworkObject.NetworkTransforms is null. I dont know why this happens, but i found that
if (type.IsInstanceOfType(typeof(NetworkTransform)) || type.IsSubclassOf(typeof(NetworkTransform)))
is always false, even when the type is NetworkTransform.CodeSnipped from NetworkObject class