Application.LoadLevel isn't resetting everything.

Firstly, I’m not using any static variables. I’m sure of that. And that’s the only thing people seemed to mention that could be causing my problem.

Here is my game. Pressing Enter restarts the game using Application.LoadLevel (0);.

The problem is sometimes it doesn’t load the hair. I have no idea why, or how to debug this.

Maybe you can fix this by modifying the script which generates the hair? I am just trying to see why he would do that

But how would I modify it? If it works sometimes, and not others, then how do I begin debugging?

It does “look” like an array issue. Are you sure your array index is not going out of bounds?

I don’t know how to check that :(. But that definitely sounds like a possible problem. Would the index not reset when I reload the game?

Anyone have any ideas?

Just check if the array.count is 0 and if it is 0 then try spawning all the hair until it is bigger than 0 that’s what I meant when i told you to modify the script.

Static variables are not reset until the program is terminated. So you will need to look after any static variables present in the code.

Just an FYI… the web demo generated a whole lot of NullReferenceExceptions for me.

@hippocoder: I said in the first sentence I’m not using any static vars.

@Dustin Horne: That’s an unrelated issue.

@Xenome: Thanks a lot. I’ll try that.

Depending on how the hair is drawn (from an array or simply random iteration) and the fact that it is “so” regular in not drawing hair but will on the next “enter”, I would be inclined to embed some of the potential trouble maker variables on the actual interface and watch their values on the redraw. Particularly the array size or the index that distinguishes which arrays are drawn…

What I’m doing to create the hair is generating a grid of hair, colliding some of that grid is a “hair shape” hitbox, and then deleting anything that didn’t collide with the hair shape. Then the hairs grow outward from that randomly. But I’m not using an array.

I would post the code but its like 3 separate scripts and doesn’t make much sense out of context.

If you are truly getting NullReferenceExceptions ( I can’t tell ) then you should look at that 1st.

An exception… even in unrelated code… can prevent other code from executing.

Or just make the variable static and clear it every time you press enter?

Exactly what I was thinking.

This problem was happening before I ever implemented the code that’s causing the NullReferenceException.