I’m currently following the lecture “Hit VFX” (#158) of the “Complete C# Unity Game Developer 3D (Updated To Unity 6)” course and ran into some issues in the last 20 seconds of the video.
Here is the issue:
The instructor sets the Stop Action of the Hit VFX Game Object to “Destroy”. This makes sense as it is supposed to remove all the instantiations of the VFX game object copies when the particle systems have finished playing. However, by doing so the original VFX game object also plays on awake and destroys itself in a matter of seconds (as it is instructed to). This leads me to an error, since now the script is trying to instantiate a game object which does no longer exist.
The error is the following:
“MissingReferenceException: The object of type ‘UnityEngine.GameObject’ has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object. Parameter name: data”
I have tried disabling the original VFX game object, but that will lead to copies being instantiated as disabled as well. I tried unchecking the “Play On Awake” checkbox, but that led to all instantiations to not play on awake. Therefore, in both these attempted fixes the copies would not play when instantiated.
How can I instantiate and destroy the copies after the original has already been played and destroyed?