Forum rules - please read before posting.

Lifting restrictions for local variables in Action

Hello, I am working with AC and encountered that local variables cannot be modified nor read in ActionList assets. When investigating the code for the ActionVarSet and ActionVarCheck, I noticed that there are restrictions in the code that prevent the script from accessing the variables. If I remove this restriction statements the ActionList still works and is able to read and set local variables.

I was wondering why this was made? I know assets should work in multiple scenes, but if I just want to make the asset for one specific scene for organization purposes I am still locked. Are there any possible errors or risks involving this that I am missing?

The restrictions I mention are something like this:

if (isAssetFile && getVarMethod == GetVarMethod.LocalVariable)
{
EditorGUILayout.HelpBox ("Local Variables cannot be referenced by Asset-based Actions.", MessageType.Warning);
return;
}

Comments

  • Welcome to the community, @Acidoswaldo.

    If you wish to make changes to AC's Actions, the best approach is to create a subclass that overrides the functions involved - and then plug it in as a custom Action.

    On the topic of local variables in assets, though - it's a safety restriction. Local variables are defined for a single-scene, while ActionList assets can be run at any time - so results will vary (or not work at all) if they affect a Local variables and are run at the wrong time.

    If you do want to have an ActionList asset reference a variable in the scene, you can use Component variables. These are variables defined in a Variables component that can be added to GameObjects - and, like other objects in a scene, can be referenced by ActionList asset files via a Constant ID component that gets auto-generated when assigning it in the Action.

    This approach is safer when it comes to running such an asset in the wrong scene, because if the Variables component is not found - no effect will be made.

  • Thank you, I will try the component variables method.

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.