Forum rules - please read before posting.

How do I start an Interaction from a script? Please help, I need an answer this weekend.

I just can't find the docs for how to do it. PLEASE HELP. I'M DESPERATE.

Comments

  • Welcome to the community, @grig.

    You're referring to an Interaction ActionList?

    This, and all ActionList types (including assets), can be run from script by calling its Interact function.

    You can find more details on accessing ActionLists through script in the Manual's "Interaction scripting" chapter.

  • Thank you so much Chris! You saved my butt!

  • Hi @ChrisIceBox , are there any examples online on how to execute this Interact function? I am trying to run it from an animation event to trigger an actionlist. I am just not good at coding. 😔

  • Information on animation events can be found in Unity's documentation.

    Is the ActionList an asset, or attached to the same GameObject as the Animator?

    If you attach it to the object, an event of the name "Interact" should be enough.

    If you want to instead run an asset, you can instead attach an ActionList Starter component that references the asset, and invoke its RunActionList function with an event.

  • I attached the ActionList to the same GameObject as the Animator.

    I found this on another post, but it says "The modifier 'private' is not valid for this item" When I put into the project.

    using UnityEngine;
    using AC;
    
    private void OnEnable ()
    {
      GameObject.Find ("BossCloseUp_Baby").GetComponent<AC.ActionList>().Interact ();
    }
    
  • edited May 5

    You need to wrap your function around a class definition:

    using UnityEngine;
    using AC;
    
    public class MyScriptName : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            GameObject.Find ("BossCloseUp_Baby").GetComponent<AC.ActionList>().Interact ();
        }
    
    }
    

    Be aware that you can't prefab ActionLists, however. If your character is a prefab, set the ActionList's Actions Source to Asset File and have it reference a separate ActionList asset. You don't need a custom script - invoking the ActionList's "Interact" function with the event is enough.

  • This worked, Thank you so much @ChrisIceBox , luckily it's not for a character, but will keep it in mind.

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.