Spawned object occassionally don't move or get stuck

I’m making a little zombie shooter game (very simple - I’m new!) which spawns zombies, and friends to save. Everything seems to work fine, but sometimes a newly spawned character will just get stuck in its spawn location (set randomly each time). The coding I think is fine because it works 95% of the time and when it doesn’t, it’s like the script that moves them hasn’t loaded because not only do they not move, their animation doesn’t play either.

It does this with both the zombies, which are Instantiated randomly from an array of prefabs, and with the friends, which are using a pooled object of a single prefab. So the same prefabs are being used over and over again, and normally, they work, but sometimes they get stuck.

The code is all on Github, if it helps - GitHub - davide1a/Zombie-Attack: My Zombie game

Perhaps.

But that won’t be a constructive way to think about it.

Instead it is time to think of all the possible things that might be wrong (code and otherwise… software has to be 100% complete or it is broken) so you can have a chance of finding out what is wrong.

… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

check if they spawn inside the navmesh area. because else they can’t move.

are you using premade assets or frameworks from the asset store?

Thanks for the suggestions. I’m not using a navmesh on this. Didn’t even know what it was!
Some extra debugging helped. In fact, I didn’t even have to go as far as actual debugging, just thinking about what I could try to debug made me realise you were right, and my code wasn’t correct at all! :sweat_smile:

Turns out, I was setting an isDead bool if the friends got attack (or shot by me!) to stop them moving, but then not resetting that for them to be reused from the pool.

If anyone gets bored!