Hi,
i am having trouble starting an ActionAnimChar Action through code.
ActionCharAnim customCharAnim = ScriptableObject.CreateInstance();
customCharAnim.editingAnimEngine = ???
customCharAnim.isPlayer = false;
customCharAnim.animChar = GetComponent<Char>();
customCharAnim.clip2D = availableAnimations[index];
customCharAnim.method = ActionCharAnim.AnimMethodChar.PlayCustom;
customCharAnim.layerInt = 0;
customCharAnim.doLoop = false;
customCharAnim.willWait = true;
customCharAnim.idleAfter = true;
customCharAnim.idleAfterCustom = true;
customCharAnim.Run();
the problem seems to be the editingAnimEngine, which i have no idea of referencing. We are using a custom animation engine for this, but i wouldn't even know how to reference a non monobehaviour class (which includes all the supported ones as well). Any help here would be great.
AC version: 1.70.2 -> Unity 2019.3.1f1
Sincerely,
Max
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Is this all happening at runtime? There's no need to define editingAnimEngine if so - since it's only used to update the UI in the ActionList Editor / Inspector.
The real issue here seems to be that you're trying to run the Action directly by calling its Run() function. This won't work if the Action has to run multiple frames (which is does in this case because you're setting willWait to true).
See the ScriptedActionListExample script for a guide on how Actions can be set and run at runtime. You can condense a lot of the above into the static CreateNew function, and then tweak as necessary, i.e.:
(Don't worry about "Mecanim" in the name - it doesn't set the animation engine, only the relevant fields).
hi, with your reference and the hint to the ScriptedActionListExample script it was easy to solve.
thx Chris, works like a charm
here is the running solution, createActionList() of course from the ScriptedActionListExample script.
ActionList actionList = CreateActionList();