Forum rules - please read before posting.

starting ActionCharAnim from code

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

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.:

    ActionCharAnim charAnim = ActionCharAnim.CreateNew_Mecanim_PlayCustom (GetComponent<Char>(), availableAnimations[index]);
    charAnim.idleAfterCustom = true;
    

    (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();

            // Make sure we're in gameplay and that no Actions are already running
            if (actionList.AreActionsRunning() || !Application.isPlaying)
            {
                Debug.LogWarning("Cannot run Actions at this time", this);
                return;
            }
    
            ActionCharAnim customCharAnim = ActionCharAnim.CreateNew_Mecanim_PlayCustom(GetComponent<Char>(), availableAnimations[index]);
    
            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;
    
            actionList.actions = new List<Action>
            {
                customCharAnim,
            };
    
            actionList.Interact();
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.