Entities spawning in (0,0,0) and then teleporting to correct position

I'm instantiating a projectile when the user clicks, as follows:

/* ... */
if (cmd.IsFirstExecution)
{
if (cmd.Input.Fire)
{
BoltNetwork.Instantiate(BoltPrefabs.Projectile, player.position, Quaternion.identity);
}
}
/* ... */

The owner of the projectile is the server, and then the transform is synched as always:

public override void Attached()
{
state.Transform.SetTransforms(transform);
}

Now, it happens that sometimes i can see the projectile, as it spawns, teleporting from (0,0,0) to the player. How can I solve this?

I tried deactivating every visual component on the projectile prefab (renderers, particles, etc), and reactivating them in the Attached() method, but it doesn't fix the problem.

Any help is appreciated!
matteo

Best Answer

Answers

  • Are you sure to have the BoltNetwork.Instantiate() code only run on the server?
  • @Symptom Yes, the Instantiate is inside an if (entity.isOwner) block, where entity is the player prefab instance, which is owned by the server. I think @ashoulson is right...
Sign In or Register to comment.