Hi, I’m doing an asteroids game for study purposes, the asteroids, bullets and extra lives are spawned using object pooling with a singleton. Everything works fine, but when I finish a game and try replay, I get this when trying to shoot.
MissingReferenceException: The object of type 'UnityEngine.Transform' 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.
UnityEngine.Object+MarshalledUnityObject.TryThrowEditorNullExceptionObject (UnityEngine.Object unityObj, System.String parameterName) (at <b5bf0c891ea345fe93688f835df32fdc>:0)
UnityEngine.Bindings.ThrowHelper.ThrowNullReferenceException (System.Object obj) (at <b5bf0c891ea345fe93688f835df32fdc>:0)
UnityEngine.Transform.SetParent (UnityEngine.Transform parent, System.Boolean worldPositionStays) (at <b5bf0c891ea345fe93688f835df32fdc>:0)
UnityEngine.Transform.SetParent (UnityEngine.Transform p) (at <b5bf0c891ea345fe93688f835df32fdc>:0)
UnityEngine.Transform.set_parentInternal (UnityEngine.Transform value) (at <b5bf0c891ea345fe93688f835df32fdc>:0)
UnityEngine.Transform.set_parent (UnityEngine.Transform value) (at <b5bf0c891ea345fe93688f835df32fdc>:0)
SpawnPool+PrefabPool.SpawnInstance (UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, UnityEngine.Vector3 scale, UnityEngine.Transform parent) (at Assets/_Data/Scripts/Logic/SpawnPool.cs:33)
SpawnPool.Spawn (UnityEngine.Transform prefab, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation, UnityEngine.Vector3 scale, UnityEngine.Transform parent) (at Assets/_Data/Scripts/Logic/SpawnPool.cs:133)
SpawnPool.Spawn (UnityEngine.Transform prefab, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at Assets/_Data/Scripts/Logic/SpawnPool.cs:127)
PlayerController.OnFire (UnityEngine.InputSystem.InputValue inputValue) (at Assets/_Data/Scripts/Player/PlayerController.cs:92)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
Additionally, asteroids and lives do not appear either.
This is how I manage Scenes:
I would appreciate a lot some help on this topic ![]()


