Glitch Garden - Unable to spawn infinite lizards

I’m following the Glitch Garden project. The first time around after applying all in the spawners game object, I noticed that only a few lizards were created. I also noticed that I got this error. Now that I’ve applied version control, I’m still getting this same error. I believe the lizard has been destroyed but I might be wrong. I’m putting this in case anyone might know.

MissingReferenceException: The object of type ‘Attacker’ 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.Internal_InstantiateSingle (UnityEngine.Object data, UnityEngine.Vector3 pos, UnityEngine.Quaternion rot) <0x34a00570 + 0x00062> in <5ac29b9d51934dd39a8dce946b9985a7>:0
UnityEngine.Object.Instantiate (UnityEngine.Object original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:211)
UnityEngine.Object.Instantiate[T] (T original, UnityEngine.Vector3 position, UnityEngine.Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.bindings.cs:285)
AttackerSpawner.SpawnAttacker () (at Assets/Scripts/AttackerSpawner.cs:27)
AttackerSpawner+d__4.MoveNext () (at Assets/Scripts/AttackerSpawner.cs:19)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

Hi,

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring.

Maybe something in your scene got referenced, destroyed, and now the code tries to instantiate that destroyed game object. Or something else is going on. Without knowing to which line the error message refers, it is difficult to tell where to look for the issue in the AttackerSpawner class/instance.

Hi Nina,
I found the problem. My guess was right. My original lizard happens to be on the same row so when the lizard is spawned, the attacker prefab shows it’s empty. All I did was to move the lizard to a different position. Now I get a different error message.

What error message do you get?

NullReferenceException: Object reference not set to an instance of an object Projectile.OnTriggerExit2D (UnityEngine.Collider2D otherCollider) (at Assets/Scripts/Projectile.cs:36)

Did you try what I suggested in the first paragraph of my first answer in your thread?

Hi Nina,
Yes I checked what you said and I found that the main spawner group item is the culprit. When I played the game, the error message only showed then the spawner showed that the lizard was empty.

Remove the reference to the Lizard from the field in the Inspector and assign the prefab from your Assets folder to it. Then check your code and make sure that the variable does not get overridden by anything.

Hi Nina,
Yes I’ve done that. The lizard from the prefab was assigned.

Update: The error is pointing to the projectile script. The line affected is the last in the script.

    health.DealDamage(damage);

This one. Any idea why this should cause issues?

Check with a Debug.Log whether health or damage is null.

Hi Nina,

Yes, in fact it is null. I’m not sure as earlier on everything was ok.

    Debug.Log(health);
    health.DealDamage(damage);

My error message is now:

Null
UnityEngine.Debug:Log(Object) Projectile:OnTriggerExit2D(Collider2D) (at Assets/Scripts/Projectile.cs:35)

NullReferenceException: Object reference not set to an instance of an object Projectile.OnTriggerExit2D (UnityEngine.Collider2D otherCollider) (at Assets/Scripts/Projectile.cs:36)

Check where an object is supposed to get assigned to the health variable. Check the value of the variable there. If it is not null, the assignment worked but the reference gets lost at a later juncture. If that’s the case, there are two potential reasons: a) the Health object got destroyed, b) the health variable gets overridden at some point.

Nina,
I’m in the midst of repairing my laser defender project. The unity team is still working on the path 0 that suddenly refused to work. Long story cut short, they don’t have any idea why the path 0 suddenly failed. They are still investigating. Whilst I got some time & energy to fix the laser defender, would you be kind enough to check which tutorial shows how to set the energy for glitch garden? If you happen to be late when I feel like checking it, I’ll just put some updates later.

At the end, once I fix the laser project, i can properly focus on this one - when I got the time.

What do you mean by “energy”?

That means if i have the mood. Sometimes a person just doesn’t feel like prioritising something. I would appreciate your help. Do take your time.

I was referring to this part. We do not have any tutorials to find “energy” and “motivation” to complete any specific game in the course.

However, if you are interested in a course on motivation techniques, you could take a look at Rick’s “Finish It! Motivation & Processes For Game & App Development” course.

Good effort to be funny. I’ll check glitch garden again later. I’m unsure what word was used. Might be “life”.

We used stars in the Glitch Garden section. See “Start Our Resource System” (currently #145).

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

Privacy & Terms