Forum rules - please read before posting.

How to ger ActionList to read a value in a GameObject?

I'm trying to do an ActionList that checks a variable in an outside object.
So far, I can get the ActionList to Call Event, calling an event on an Object, and Send Message can send a message to a GameObject.
But how do I get ActionList to get a response? Or to read a value?
For instance, to read a bool on the object so it can choose path?

Comments

  • To access an external script variable, you'll need to rely on a custom script - either a custom Action that checks for it directly, or a script that syncs the variable to an AC Variable that can then be read with the "Variable: Check" Action.

    More on writing custom Actions can be found in the Manual's "Custom Actions" chapter, and details on syncing variables with AC Variables can be found in the "Linking with custom scripts" chapter of the Variables section.

    If you can share details of what variable you're trying to access, however (i.e. name, type and script), I can see about offering more specific advice.

  • Hi
    I tried the manual, but I couldn't get it to work.
    The situation is like this. I have a script that communicates with other game systems. There, I have two methods. One is:

    public void Trigger (string triggerName)

    which tells a system to do something, using the triggerName. This one works fine in the action list editor using: Object:Call event,

    The other is:

    public bool IsCurrentState (string stateName)

    that checks if the current state is the state named stateName. But I can't figure out how to get that bool into an Action List node.

  • The most integrated way to do this would be to write a custom Acton that calls the function, and has two outputs for the bool value it returns.

    A custom "checking" Action template can be found in AC's ActionCheckTemplate script. Something along these lines should do it (replacing "MyScript" with the true name of your script):

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionCheckState : ActionCheck
        {
    
            public override ActionCategory Category { get { return ActionCategory.Custom; }}
            public override string Title { get { return "Is current state"; }}
    
    
            public GameObject obWithScript;
            public string stateName;
    
    
            public override bool CheckCondition ()
            {
                return obWithScript.GetComponent<MyScript> ().IsCurrentState (stateName);
            }
    
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                obWithScript = (GameObject) EditorGUILayout.ObjectField ("Object with script:", obWithScript, typeof (GameObject), true);
                stateName = EditorGUILayout.TextField ("State name:", stateName);
            }
    
            #endif
    
        }
    
    }
    

    A guide to writing and installing custom Actions can be found here.

  • Thanks. It worked perfectly.
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.