- Home /
Problem initialising slider value from code
I spend the whole day trying to fix a bug and with Debug.Log() calls I managed to isolate it.
I'm modifying and displaying 2 variables of an object (h and v angles), however only the first comes through for some reason:
clickableBoxRotVSlider.value = core.currentClickable.rotV;
clickableBoxRotVText.text = core.currentClickable.rotV.ToString("0.00");
clickableBoxRotHSlider.value = core.currentClickable.rotH;
clickableBoxRotHText.text = core.currentClickable.rotH.ToString("0.00");
When I at the end of my debuging tried to exchance the two, the other one got through. It seems like the code execution stops right there beween those to blocks of code.
I have no idea why this would happen.
(Moderator changed question title from "Is there such a thing as a function call limit or a stack limit in unity?" to better reflect the content)
Given you've spent so long on it I'm assu$$anonymous$$g this isn't the case, but just to get it out of the way... are there any errors in the console/log at all? The most obvious cause of what you're describing I$$anonymous$$O would be that some unassigned reference is throwing an exception in the text-setting line (and that the unassigned reference is common to both V and H cases hence the exception gets thrown the first time it hits either one of those lines).
no, my console is absolutely clean. No errors, no warnings. (and yes they are turned on).
The code is just as that above, but clickableBoxRotHSlider.value stays on its old value while the new value is diffenent. When I cut the first 2 lines and past them unter the other two, then those don't seem to be executed. Thats really weird.
Hi i am getting a similar behaviour. Can you please help me?
If the cause is the same then the solution will be the same. If it's not then you need to provide more details.
With regard to the solution posted here (in the OP's own Answer) - this is a common pitfall. If the slider already has a callback assigned, then that callback will be called when you set the value through code, and this can lead to complications. You could probably diagnose it with lots of Debug.Logs telling you the value of the slider(s) before and after each assignment, and within the callback function.
Sometimes it can make sense to add the callback function through code, following initialisation, so that it's not invoked on initialisation. In the OP's situation it looks like the two sliders' values are dependent on each other, and it makes sense that that would create a need for more complex logic.
If that doesn't help, you should create a new question, with details of your set-up/code and problem (and link to it from here).
PS I've converted your Answer to comment because Answers are for answers to the question posted, not comments or follow-up questions.
Answer by antx · Dec 08, 2015 at 12:37 PM
Okay, I found out that the moment I set the value of the first slider it fires its callback function for changed value. This callback function got executed before the next line of code and alters the variable that I was going to initialize the second slider with. That way it looked like the following code is not being executed anymore.