Has anyone come across this kind of problem with vars?

This is the kind if thing that is holding me up at the moment. Of course this isn’t the whole script but to summerise. NumberOfAliens gets called from another script, and reports the correct value. The one in Update only ever reports the initial value.

It looks like even though this is supposed to be reporting the same value, the one in update is reporting the value in the prefab for some reason.

How do I get round this?

var numberOfAliens : int;

function NumberOfAliens() : int
{
    return numberOfAliens;
    Debug.Log("NOA function output + " numberOfAliens);
}

function Update()
{
    Debug.Log("Update NOA output" + numberOfAliens);
}

I’ve done some more tests and it the value in the heirarchy isn’t getting changed, however the value in the prefab does get changed. This seems to be my problem. I’ve initialized an instance of WaveControl except Unity seems to be wanting to use the prefab.

Why is this?

If you are using public vars the values in the script do not necessary tally with the values in the inspector. So to make sure your values get updated, you should reset your inspector. But clicking on the gears icon on your script component then reset. :smile: Hope that works.

Right - I’ve made a right mess of my understanding but the light has just dawned.

What I was doing was creating GameObject references to my WaveControl object throughout the various scripts. Then in the main code I was actually using an instance of it. My code was set up to use dragging and dropping so this never worked as in all the other references it only pointed to the prefab and not the instance. How the game even worked at all is beyond me!

I have a fair bit of work to do but I’m glad I figured it out.

I’ve made all the changes and it works now. I can’t believe what I’d done, or even thought would work. That was a proper face-palm moment.

This is a bug that I’ve been living with since I started using Unity! I feel like a new dawn has broken.