Forum rules - please read before posting.

Running an action with custom parameters by script.

Hi!

I try to run an action by script. I am aware of myActionList.Interact() but I want to directly call an action because I have to change parameters dynamically.

Specificly I want to set a new standard animation by code.
This is what I have but the action seems to not get called:

ActionCharAnim animAction = ActionCharAnim.CreateNew_SpritesUnity_SetStandard(character, AnimStandard.Idle, "idle1");
                animAction.Run();

Isn't that how it should work?
It doesnt have any effect.

When I call the set standard via an actionlist my script works fine but I need a solution which is dynamic.

Thank you!

Edit: Just saw that I posted in the wrong forum.. should probably go to Technical Questions.

Comments

  • Actions can only be run inside of an ActionList. After creating an Action through code, you'll then need to place it inside an ActionList - and then run the ActionList itself.

    ActionList actionList = GetComponent <ActionList>();
    if (actionList == null) actionList = gameObject.AddComponent<ActionList> ();
    
    ActionCharAnim animAction = ActionCharAnim.CreateNew_SpritesUnity_SetStandard(character, AnimStandard.Idle, "idle1");
    actionList.actions = new List<Action> { animAction };
    actionList.Interact ();
    

    See the included ScriptedActionListExample script for a demonstration on how Actions can be generated at runtime.

    When I call the set standard via an actionlist my script works fine but I need a solution which is dynamic.

    You may have other reasons for generating an Action through code, but it's not the only way to have Action fields be dynamic. You can override fields of existing Actions through ActionList parameters. In the case of the Character: Animate Action's Clip field, this can be overridden with a String parameter.

  • Ah I missed that! Thank you!

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.