Correct way to destroy gameobject
Options
Hi!
What is the correct way to destroy a gameobject from a script attached to it?
I tried it with this:
public void OnSyncedCollisionEnter(TSCollision2D otherBody)
{
if (otherBody.gameObject.tag == "Wall")
TrueSyncManager.SyncedDestroy(gameObject);
}
This works well offline but leads to errors when playing with two players.
Thanks, John
What is the correct way to destroy a gameobject from a script attached to it?
I tried it with this:
public void OnSyncedCollisionEnter(TSCollision2D otherBody)
{
if (otherBody.gameObject.tag == "Wall")
TrueSyncManager.SyncedDestroy(gameObject);
}
This works well offline but leads to errors when playing with two players.
Thanks, John
0
Comments
-
Longer description: So I open a 2 player game. There each player controls a character who is able to shoot bullets. After the bullets hit something, they destroy themself (using the code in the previous post). But after I shoot several bullets, one of the clients stops working, telling me an error. I think this is because he is in the middle of a network-rollback of a step. And as the bullet is already destroyed, he isn't able to re-access it.0
-
Hi @John05,
Thanks for the report, "SyncedDestroy" is the recommended way to destroy a GameObject, we are going to check it.0 -
Can you provide us a log of the error?0
-
0
-
@JeffersonHenrique With your guiding here I was now able to use the most recent version of your asset and it seems that the game now runs more smoothly and the error doesn't occur anymore.
Thank you!0 -
0