Entities spawning in (0,0,0) and then teleporting to correct position
Options
matte
✭
in Photon Bolt
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
/* ... */
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
0
Best Answer
-
I am having this issue as well.
I believe it's because the entity is spawned at the correct position, but the transform is instantiated as having all zero values (because the client hasn't received a state update yet) so the transform moves the object back to the origin. Then later the transform gets the state update and moves to the correct position again.
I'll link the github issue to this thread.5
Answers
-
Are you sure to have the BoltNetwork.Instantiate() code only run on the server?0
-
I am having this issue as well.
I believe it's because the entity is spawned at the correct position, but the transform is instantiated as having all zero values (because the client hasn't received a state update yet) so the transform moves the object back to the origin. Then later the transform gets the state update and moves to the correct position again.
I'll link the github issue to this thread.5 -
@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...0