How do set the initial position of a rigidbody with a network transform.

I have a button that spawns in a gameobject with a Network Rigidbody and a Network transform.

The game object prefab is at (0,0,0). But If I want to set an initial position to (-3,0,0), what I see on the client is an object spawning at (0,0,0) then quickly sliding into place at (-3,0,0).

Even if I look carefully on the server instance, I see a brief flash where the object is at (0,0,0).

What am I missing here?

public class RobotControl : NetworkBehaviour
{
    new private Rigidbody rigidbody;

    public Vector3 defaultPosition = new Vector3(-3, 0, 0);

    public override void OnNetworkSpawn()
    {
        if (NetworkManager.Singleton.IsServer){
            rigidbody = GetComponent<Rigidbody>();
            rigidbody.position = defaultPosition;
        }
    }
}

I’m running netcode 1.2.0

This is an older post but for anyone else that comes across, I found calling rigidBody.MovePosition(customPosition) will work. (edit to update move position)

thx. This helped me out in setting my own spawn points. To clarify though. rigidbody does not have SetPosition but MovePosition.

1 Like

You’re right, I was typing too fast! MovePosition is what worked for me.