In my code i set two slider values (this happens in the start function) but for somehow it didnt work. i checked it and found out the code below it doesnt get called either. so i placed Debug.Logs to check where it is and ended up with these two lines. (when removing these the code worked again)
//mouseSpeed and volume are both an INT
Debug.Log("works1");
mouseSpeedSlider.value = mouseSpeed;
volumeSlider.value = volume;
Debug.Log("works2");
Debug.Log(“works2”); is never shown in the console
(i also tried using floats as value with no succes)
it doesnt show any errors or warnings in the console.
if someone could explain me why this isnt working and how i should fix it that would be nice!
The error says something is accessing clickEffect of the “menu-something,” but the graphic is cut off.
None of those identifiers are in the script above. Are you using another menu manager package that might add scripts to your UI objects? Do the identifiers in your script snippet above map to properties that use those identifiers?
the error is caused because its trying to acces a object which is declared after the code i showed in the picture.
i have them selected in the inspector (shown in the image below)
and like this in the code:
public int mouseSpeed;
public int volume;
public Dropdown resDropdown; //this is not part of the problem
public Dropdown qualityDropdown; //this is not part of the problem
public Slider volumeSlider;
public Slider mouseSpeedSlider;
Note that it is normal for the rest of a function to not execute after hitting a null or unassigned reference error. You go to the line of code indicated by the error, figure out what references are being used on that line, and then figure out which one is null. Then make it not null.
line 42: “clickEffect = this.gameObject.GetComponent();” is never called. because of this line 83 “clickEffect.Play();” (and everywhere i have this code) is returning a error (cant play if the clickEffect isnt set).
(line 24 is temporary public and is normaly private but i changed that while testing)
everything below line 39 “volumeSlider.value = volume;” isnt called or executed.
when i remove line 38 and 39 (the ones i showed in the question, marked as line 3 and 4) it works perfectly.
when removing only 1 of them the problem is still there so both of them are causing it.
so i know the problem is caused by these 2 lines. now i checked if i had the correct sliders selected in the inspector. which i have.
both are set in the inspector. and both are causing the problem because when i remove one of them it still wont work but when removing both everything works.
You probably have UnityEvent on the slider which tries to set the volume on the clickEffect?
When you set the value of the slider it will try to call that event but the clickEffect isn’t set yet. Probably. Or something like that.