Unity-Technologies / Unity-Technologies/com.unity.netcode.gameobjects

Client NetworkObjects experience Awake, Start, OnEnable, and TriggerEnter, CollisionEnter at world 0,0,0 upon instantiation

Abierto
#3,553 3 comentarios 2 reacciones 1 asignado Ver en GitHub

@NoelStephensUnity ya está trabajando en esto.

Desde el 17/7/2025.

priority:medium stat:imported type:bug
Lenguaje dominante
C#
Estrellas
2.3k
Forks
461
Merge medio
3 d 16 h
PR fusionados (30 d)
20

Descripción

Description

When a client spawns a NetworkObject via NetworkSpawnManage.InstantiateNetworkPrefab() there is no position or rotation data passed into UnityEngine.Object.Instantiate() and therefore the object is created at world 0,0,0. On a later line of code the position and rotation are assigned, after instantiation.

This means Awake, Start, and OnEnable are all called when at world 0,0,0 -- this is arguably expected and why you have OnNetworkSpawn.

However, OnTriggerEnter (and probably OnCollisionEnter) also fire for things at world 0,0,0. That problem is outside of the scope of the OnNetworkSpawn warmup in my opinion.

Developers should not have to write custom code to handle this problem when the position and rotation could simply be passed into the instantiation.

internal NetworkObject InstantiateNetworkPrefab(GameObject networkPrefab, uint prefabGlobalObjectIdHash, Vector3? position, Quaternion? rotation)
{
    Vector3 defaultPosition = position ?? Vector3.zero;
    Quaternion defaultRotation = rotation ?? Quaternion.identity;
    var networkObject = UnityEngine.Object.Instantiate(networkPrefab, defaultPosition, defaultRotation).GetComponent<NetworkObject>();
    // networkObject.transform.position = position ?? networkObject.transform.position;
    // networkObject.transform.rotation = rotation ?? networkObject.transform.rotation;
    networkObject.NetworkManagerOwner = NetworkManager;
    networkObject.PrefabGlobalObjectIdHash = prefabGlobalObjectIdHash;
    return networkObject;
}
Environment
  • OS: Windows 11
  • Unity Version: 6000.1.3f1
  • Netcode Version: 2.4.2
  • Netcode Topology: Client-Server

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.