[Solved] False "variable not assigned" error

I’ve been looking for any solve for this, but i didn’t find anything.

My problem is that i defined material variable in my day/night cycle script, assigned skybox with shader to it, and try to change “_Blend” value of my shader to something other. It’s changing as well, but console is spamming with error “The variable SkyboxMaterial of ‘DayCycle’ has not been assigned.” every frame.

Code:

var SkyboxMaterial : Material;
var SkyboxBlend : float = 0.0;

function Update(){
SkyboxMaterial.SetFloat("_Blend", SkyboxBlend);
SkyboxBlend = 0.5;

}

Any help?

Bump

does the skybox material show up in the parameters section of DayCycle? are there any snippets of code that could change the value of SkyboxMaterial?

It shows up, and there isn't any code which could change it.

Bump

3 Answers

3

The only reason i see here (It’s working and shows such and error) is that you have your script attached to at least two gameobjects. One with the material reference and one without. Type the name of your script “DayCycle” in the search box above the hierarchy window now you should see at least two objects. All objects that show up have this script attached.

Thanks for help. Now, it works!

You need to attach a Material in editor to it or make

SkyboxMaterial = new Material();

in code

"The type 'UnityEngine.Material' does not have a visible constructor that matches the argument list '()'." I think it's just a bug, 'cause everything is working, but console is spamming with error.

From what I see…

“SkyboxBlend = 0.5”

Should have a…

“;” on it. so maybe…
“SkyboxBlend = 0.5;”

SOrry if that didn’t help. But that’s how I fix this error in myscripts

It's my bad adding this answer, in my code there is a semicolon at the end.