Broke the game somehow

Heya, so i made another mistake but dunno how…
there is a short gif of it. https://gyazo.com/8d7be027095a14f00c709e0a49443cdf
when the game starts, it creates the wave(s) but instantly despawn it… ive only done as video, however i found someother sprites from kenney i used, but i duplicated previous enemy, and just applied the new sprite to it.
i dont know what to show you, since there havent been any real code changes in this lecture, only removing the serializedfield from the shotcounter… it now also produces this error:
error


a side question is that im using a missile sprite now from the new enemy, but it shoots it reversed(with the bottom first) i have changed the rotation on the prefab with 180 degree on X axis, but it doesnt change the direction of the sprite… but this is a side problem…

okay update: i found out i had put the waypoints in my wave1 outsie of game, and that made the issue, with instantly despawning. so thats fixed now. but im still getting spammed with those errors :frowning:

A NullReferenceException occurs when an object referenced by a script either does not exist or cannot be found at runtime. The errors seem to be pointing to lines 16 and 28. That probably means your list of waypoints isn’t being populated. Could you share a screenshot of your GetWaypoints() method in your WaveConfig script?


there is my WaveConfig i havent edited it for some lectures now.

I’m not seeing where waveConfig is being instantiated. Is this something you’ve been dragging and dropping in the editor? If so, I would check the inspector and see if it’s still there.

Edit: Alternatively, if you’re not dropping it in the inspector, you can instantiate in the Start() method using the default constructor. waveConfig = new WaveConfig(). If you have one in the scene and you want to grab that, you can use waveConfig = FindObjectOfType<WaveConfig>().

i think i dragged it onto the “enemy spawner” when it got made in some previous lecture

Weirdest stuff just happened. i was trying changing the paths used in the waveconfig, and now the error is gone… and everything works… ill just restart unity to see if it stays working…
But anyone have a fix for my missile not being rotated ? :S

Links like that get broken all the time. That’s the reason I generally prefer to do as much of that stuff in code as possible. Do you have a shot of the code where your missile is being instantiated?

hmm i think i know what the problem is then from your question. im using the same Fire method as the one im using on the regular enemies with the laser shots, and there i dont have to rotate the shot. So i would have to make an all new method to handle the missile projectile for being able to rotate it ? i thought i could do it by simply adding rotation on the sprite inside unity.

im getting this error now( im starting to dislike this game…)
im getting it once i press start game. im guessing its because i call for ResetGame in same code as im starting the game with. so it cant reset since its the first time, and therefore not instansiated yet
level15


Typically would imply the game object doesn’t exist, you could use a try statement and instead of just finding the game object maybe set it to a variable on load. But make sure this script runs after the Singleton.

For the projectile thing, the code looks fine. You say you rotated the sprite, have you tried re-adding the changed sprite to the projectile prefab? They don’t always update automatically.

For the resetting thing. Try just popping one into your scene hierarchy, that way your script doesn’t get hung up there. I remember a similar thing with the singleton in the block breaker game.

hmm k, im pretty newbie, but ill look it up how to do a try statement!

i found an online sprite editor and simply rotated the image there, and then just applied the new sprite.
what do you mean with the “try popping one into the scene hierachy” i know what the scene hierarchy is, but im not sure what u want me to put in there.

Simple as can be

try {
    YourMethod();
}
catch (Exception e) {
    Debug.Log("Caught my error");
}

Basically, it stops the script from causing a problem when an error is caught. You can build in custom error handling as well, when you get the hang of it.

You could skip the try for now, but assign the gameobject to a variable

GameObject gameSession = FindObjectOfType<GameSession>()

An instance of an object with the GameSession script on it.

This topic was automatically closed after 14 days. New replies are no longer allowed.

Privacy & Terms