FANDOM


Note: this is useful when you need to perform repeated/automated chains of actions, or you simply want to harness the power of AC actions right within your script. Also to note, at least some basic understanding of C# is required to apply this technique.

First off, you need the script file's name. In this case we will use Character:Face Object. So, navigate to the Actions folder, inside your Adventure Creator's folder. To find the file, you may need to open some of the scripts to figure out if it's the right one or not (the scripts aren't always named the same as the actions). So, with a file open, all you need to do to verify if it's the one you want, is to scroll down until you reach the action's description. There you will easily be able to confirm the name of the action. In this case the name of the file containing the action is: ActionCharFace.cs

The second step is to take a look at the parameters you will need. For most cases all you need to do is observe the parameters you select in a regular actionlist. That'll tell you the numbers of variables you will need to provide data to and also the amount of variables and the possible names the variables may have inside the script. In this case, we want to have a character turn to face the camera, so the important variables are:

                public bool isInstant; //optional
		public Char charToMove; //needed for the script to move the char
		public GameObject faceObject; // who or what to face
		public bool facePlayer; //optional
		
		public CharFaceType faceType = CharFaceType.Body; //default is OK here
		public bool isPlayer; //if it's the player

It's also important to note that using the actions this way will not run the ShowGUI() funtion in the action, which only runs in-editor, so any variables set or initialized there depending on some user selected options (such as Is Player in this case) will need to be filled manually, as in the example below.

Anyway, now we know all these, we can begin.

To use an action we will need to create a temporal instance of the script at runtime. Usually you do this using a variable declaration with a "new " keyword. Like so:

public Vector2 HotSpot = new Vector2(30,30);

But, all AC actions are scriptableObjects, so that isn't possible. Instead you use "ScriptableObject CreateInstance". Like so:

ActionCharFace myActionCharFace = ScriptableObject.CreateInstance<ActionCharFace>();

With this we have created an instance of the script, which is basically floating in the ether. that's because ScripableObjects don't need to be attached to an object to be instanced. Once the script instance is created, we can simply feed the new script with the parameters by simply filling out its variables. Like so:

myActionCharFace.isPlayer = true; //or not true if you don't want to.
myActionCharFace.faceType = CharFaceType.Body;
myActionCharFace.charToMove = GetComponent<Char>();//assuming script is on character
myActionCharFace.faceObject = SomeGameObject; //the game object to face

Lastly we call the Run() method stored in the script's instance. like so:

myActionCharFace.Run();

This will take the data inside the variables we filled out and run the function. Juts be aware that some scripts don't use the Run() function to work. Action:Check State (ActionMenuCheck.cs) for example will use CheckCondition() instead, so make sure to take a quick look at the script to confirm which function will trigger the action.

And now you should be able to call AC actions from your scripts. Cheers!

-Tip provided by Alverik-

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.