Destroy(gameObject) order of operations

Hi there,
In the lecture I notice that we are calling Destroy(gameObject) before other lines in the same class are called (level.BlockDestroyed, TriggerSparklesVFX). I’m by no means an expert but my experience has been that Destroy needs to be the last function called to prevent things like Null Ref errors. Is this best practice or am I missing something else?



Hi Dan,

Destroy does not destroy a object immediately but with a delay. For this reason, it does not matter where you call it in this code block. However, I agree with you. For representing the idea (do this, do that, then destroy), it would make more sense to put it at the end. For this reason, I usually move it at the bottom of the method code block. Please feel free to do the same. :slight_smile:

See also:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms