Enum Inside of animator stopping using of enum++;
Hello! I am building a combat system in unity using a couple ENUM's. One of these ENUMS is public and is used to increment the basic combo from 1 - 2 - 3. This works fine and has for days. However, I added in another animation, and in the animation, I set that enum to 4 at the very start, and 0 at the end. This means that it doesnt increment the enum anymore through the usage of enum++ and always seems to snap back to enum 0 despite me not having any code that WOULD force it back in place. Any input would be amazing, thank you!
Answer by ItsTheConnection · Mar 13 at 08:11 AM
I'm not sure what you mean by ENUM in this case, I can only suppose it is an integer parameter inside the AnimatorController.
If I get it correctly, you are using either curves or animation events to set said value. Be aware that sometimes Animation Events may not fire if they are placed inside the range of a transition.
As an example:
A---------------A--------------------
----------B---!--------------B-------
If ! is the event, it will not fire as the transition is occurring.
That might be the main reason why your value is not being set correctly.
I dont think that is it, here lemme provide some photos and a code snippit to assist! Sorry my terminology isnt quite as good as I would like it to be! So essentially, the highlighted integer paramater seems to be stopping me from incrementing my values in code, as when removed, both setting it as tackle, and currMeleeCombo++; Work fine when the parameter isnt in the animator, however when it is there am unsure as to why it is halting it from being changed in code.
if (currMeleeCombo != MeleeCombat.None && currCombateState != CombatScriptTest.CombatState.DirectionalLock)
{
currCombateState = CombatScriptTest.CombatState.TrackForward;
}
else if (currCombateState != CombatScriptTest.CombatState.DirectionalLock)
{
currCombateState = CombatScriptTest.CombatState.None;
}
if (Input.GetKey(KeyCode.Mouse0) && !basicComboLimiter)
{
currMeleeCombo++;
timerBasicCombo = timerBasicComboTimeFrame;
timerBasicComboLimiter = timerBasicComboTimeFrameLimiter;
if (currMeleeCombo == MeleeCombat.Punch1)
{
_Networkanim.SetTrigger("Punch1");
}
if (currMeleeCombo == MeleeCombat.Punch2)
{
_Networkanim.SetTrigger("Punch2");
}
if (currMeleeCombo == MeleeCombat.Punch3)
{
_Networkanim.SetTrigger("Punch3");
}
}
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.F))
{
currMeleeCombo = MeleeCombat.Tackle;
_Networkanim.SetTrigger("Tackle");
}
Ook I think I see what you mean now.
Just one little pieace of info is left to understand, does the value change through code when the 4th attack animation is NOT playing? Probably not if I understood correctly.
I think the problem might be one of the following:
1) The clip doesn't exit once it's finished, therefore it continuously sets the value
2) The clip does exit, but since it does set the value at least once, the other animations will "pretend" they write it too by using its default value. This should be solved probably by un-checking the Write Defaults variable on each clip that shouldn't set the value. (you can find it by selecting the state on the animator and looking in the inspector)
If neither of these things work I'm not sure what the issue would be then :/
P.S. Sorry if I'm not adding links/sources but from mobile is kinda hard
Unchecking Write Defaults didnt seem to lead to the answer, there was no change. Just for some added info incase this might lead to a discovery, all these animations are from the "Any State" Parameter, simply because they should be usable from any state. Im unsure if this causes some confliction.
Lastly, the issue is there even if the move is not used, therefore it is never given the opportunity to set a value. So it means its disabling any use to increment it incode. HOWEVER, it can still be used with its namespace given in code, however, it flips it back to non in a single frame.
Your answer
Follow this Question
Related Questions
[C#] Enum not working properly 2 Answers
Help! Animating hogs my Pos Y. 0 Answers
How do I modify animation parameters from script (C#) 1 Answer
Can I set one enum value equal to another enum value? 2 Answers
I Keep Getting Error CS0052 1 Answer