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

Comments

  • John05
    Options
    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.
  • JeffersonHenrique
    Options
    Hi @John05,

    Thanks for the report, "SyncedDestroy" is the recommended way to destroy a GameObject, we are going to check it.
  • erickpassos
    Options
    Can you provide us a log of the error?
  • John05
    John05
    edited January 2017
    Options
    @erickpassos Sure, see the full log attached:
    pastebin.com/vDMGAMj8
  • John05
    Options
    @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!
  • JeffersonHenrique
    Options
    Hello @John05,

    Good to hear about it, any further problem we thank you for your reports.