- Home /
Why don't animation events allow you to call functions that take a bool parameter?
According to the docs, "The parameter can be a float, string, int, object reference or an AnimationEvent object."
Is there a good reason behind this? My only thought is that setting bool parameters during an animation is meant to be done somewhere else, but if that is the case, then where?
Right now I have a function which gets called at the start of each animation as an animation event:
private void SetInterruptableFlag( int interruptFlag )
{
character.CurrentActionIsInterruptable = interruptFlag != 0;
}
I know it's trivial, but I feel like I should just be able to directly set the variable equal to the value of the passed in argument instead of making an extra != comparison.
I would honestly chalk it up to deadlines. I can't come up with a reasonable explanation for why they would ignore bool arguments, apart from the idea that the animation event system is not yet fully fleshed out.
"+1" for me
Just today wanted to add a bool to my animation event.
Not allowed.
facepalm
I take the point in the question, but it makes the current situation look worse than it is... a ternary operator isn't necessary there (just use interruptFlag!=0
, it's already the bool that the ternary operator returns).
You're super right lol I must have been tired. Can't believe I didn't realize that at the time. I edited the question to use the != comparison ins$$anonymous$$d of the ternary.
Erm, why is this still an issue 7 years later? Anybody know?
Answer by M-Elwy · Feb 23, 2021 at 11:39 PM
You can use Convert.ToBoolean(INT) method.
character.CurrentActionIsInterruptable = Convert.ToBoolean(interruptFlag);
0 = False
Any non zero value = True (ex: 1, 100, -1, -100)
Thanks for the response. This is the work-around many people can use but it doesn't really answer the question of, Why do we have a float, string, int, & object parameter for animation events, but not bool?
And it's not really much of a workaround if you already have a function accepting a bool.
This question has re$$anonymous$$ded me of a similar curiosity. The PlayerPrefs class doesn't have GetBool and SetBool functions, so one gets used to using G/SetInt and doing the conversion. Not something I have a problem with in itself, but it seems odd then that the EditorPrefs class does have the Bool functions.
Your answer
Follow this Question
Related Questions
Animation Event Bool Function? 1 Answer
FindWithTag or how to find if there any instances left 1 Answer
How to fix unstable boolean values? [possible bug] 1 Answer
issue with yield.WaitForSeconds(); 1 Answer
GUI.toggle always false 1 Answer