Simple boolean problem.

I set the bool to false and true to test with debug’s if the animator is really changing.

The debug shows the bool is really being modified.

But when I check the animator, it is not changing at all.

That’s the only object I have on my scene, I don’t get how this is not working if even the debug shows the bool changing.

When you look in the animator, to see instance info like that I think you need to select the object in question (with the animator) in the scene / hierarchy.

Yup :frowning: The screenshot is actually from the animator selected from the object on the hierarchy. I never had any problems like this, feels like it should be working, I tried many ways…

Update: It gets weirder, I made a quick code to check if the bool would change on my button press, it worked, but then why doesn’t it work when the code calls it…

It is the same code from the button press method but inside of a void, what’s happening here…

I agree. There’s something funky going on, like there’s another anim you don’t know about or something. Try make a quick fresh animator with a boolean, make some code to set it and see… I mean we know this should work.

EDIT: The other obvious thing is, is this animation playing?? If it is stopped, mode changes won’t do anything.

Sorry I updated my last reply instead of making another as I didn’t saw you replied… But yeah, it surely knows the right animator to use as the code worked with button press, somehow the animator doesn’t want to change the bool when the code it’s called by any void, only worked on update with button press.

And yet you’re seeing the debug.log output… this is weird.

One thing to note (and I do NOT think this is your issue), is that the enabled identifier already exists when you inherit MonoBehaviour. I know what you’re using above there is a local variable, but if you reuse that identifier somewhere else, weird things can happen. You would probably see a warning about “hiding inherited value” if you made a bool enabled; class variable.

Some new tests:


Although it says it is currently ‘true’, it shows false.

But at least I discovered something weird, when I set the bool as ‘true’ or ‘false’ instead of the void bool name ‘setBattleMode’:


It worked, but that also doesn’t make sense because as the debug’s showed, ‘bool is set to become: True’ (setBattleMode), the problem isn’t really there.

The code:

The debug’s results:

And the animator results:

This is legitimately making me sad. I even renamed the parameter’s name so I could be sure ANYTHING ELSE wasn’t modifying it.

Change one of your log statements, adding a GameObject parameter like this:

Debug.Log("Bool is currently: " + playerAnim.GetBool("battleMode"), playerAnim.gameObject);

Then when you see that log, click on it. It will take you to a GameObject somewhere in your project. Either in the hierarchy, or in the project window or something. It may take you to a different object than you expect, which could reveal something about your issue.

1 Like

Thank you so much for this, I always wondered how to link objects to the console log. Unfortunately it takes me to the right object, the one supposed to change, which makes it even weirder that the boolean doesn’t change.

Make a new separate boolean called “YabbaDabbaDoo”.

In the piece of code that sets the battle Mode boolean, the part of the code that appears not to work, ALSO set that “YabbaDabbaDoo” to the same values, and see if it gets set / cleared.

I think something else is running and clearing your battle mode boolean before end of frame.

1 Like

Did the test you said, but none of the two booleans changes unfortunately. :cry: I’ve tried asking on reddit about this same problem, was a bad idea, everyone called me dumb, but one guy had a good idea, said I should try to update the animator (animator.Update()) after changing the bool to see if visually the bool would change, as the Debug said it did, but that also didn’t work.

At this point I think some kind of glitch is happening, I’m at the recent new Unity 2020.3 LTS, I really don’t see any reason to the problem to be happening.

Remake the animator! Or at least make a clone of it and use that. I mean at this point why not.

Ah, Reddit. :slight_smile:

1 Like

And there we go! You take the trophy. I cloned it and it did not work, but as you said ‘at this point why not’ I decided on re-creating it completely, comparing it side by side, and well now it works, maybe the file itself had any problem, so cloning it would leave the problem to the clone too? Guess I’ll never really know, but I’m glad it is working just as it should now, and I’m very grateful you helped me through this! :wink:

Well the controllers are text files and you could compare them… but a lot of stuff won’t matter. Who knows, maybe somehow your property became called "BattleMode " with a space at the end or something silly and invisible like that.

Oh man, I was only joking but looks like Unity actually LETS you put a space inside a property name!!!

This one is called "zaboo " with a space.

6934476--814467--Screen Shot 2021-03-14 at 2.50.52 PM.png

1 Like