# In unity C#, why use the .SetBool(booleanname, boolean) command when you could just write 'booleanname = true'?

I noticed on a tutorial for unity someone used the code:

private Animator animator;
private bool isRunning = false;


While further on, did:

animator.SetBool("isRunning", true)


Why could you not just do

isRunning = true


if it is in the same class?

These two lines do different things.

animator.SetBool("isRunning", true)


This sets The Animator's isRunning parameter to true - which is likely to affect which animation state it selects / blends to within its animator control graph.

isRunning = true;


Sets this script's isRunning member variable to true. We can't see much of how this script functions or even what it is called in your example, but it sounds like it's used for local book-keeping of gameplay state, so that your control script knows it's in the "running" state and can make control decisions differently informed by that fact.

isRunning = true will not automatically change your animator's parameter states or affect how it selects animations to play. animator.SetBool("isRunning", true) will not set your control script's member variable to affect its control logic.

Depending on the design of your control script, you might need to set both the animator parameter and the control script's member variable in the same places, to keep the internal control model consistent with the animated "view" of that model state.

• I see, it was the boolean within the anmator rather than the script – Ronnie Lightweightbaby Coleman Dec 9 '19 at 10:14