Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Mirror network] Instantiated object spawns in 0,0,0 for a few ms

Discussion in 'Scripting' started by illift, Apr 24, 2021.

  1. illift

    illift

    Joined:
    Dec 6, 2018
    Posts:
    1
    Hi,
    I am coming to you to ask you for help because I have been blocking for several days on a slight problem with Mirror.

    When I instantiate a gameobject (rigidbody + NetworkLerpRigidbody script) on the network, on clients, the gameobject spawns a few milliseconds on 0,0,0 location before being synchronized via the NetworkLerpRigidbody script and being teleported to its correct location.

    However, when I instantiate the object at the server, I give it the correct location before using NetworkServer.Spawn()

    The prefab is registered on NetworkManager and has NetworkIdentity

    Code (CSharp):
    1.  
    2. [SerializeField] private GameObject m_SpawnPoint;  //spawn point is empty gameobject on the scene
    3. [SerializeField] private GameObject m_GobPrefab; //its a prefab and its registered on NetworkManager
    4.  
    5. ...
    6.  
    7. if (!this.isServer)
    8. return;
    9.  
    10. GameObject gob = Instantiate(m_GobPrefab, m_SpawnPoint.transform.position, m_SpawnPoint.transform.rotation);
    11. gob.transform.position = m_SpawnPoint.transform.position;
    12. NetworkServer.Spawn(gob);
    13.  
    I have also already tried to put the rigidbody in kinematic and to do an Rpc to deactivate the kinematic, but the object still spawns like subliminal image in 0,0,0 position for some ms...

    I'm not sure what to do, if it's me doing it wrong or it is a mirror problem?

    sorry for my bad English,

    Thank you.
     
    Last edited: Apr 24, 2021
  2. Setzor

    Setzor

    Joined:
    Mar 10, 2014
    Posts:
    10
    did this ever get figured out