Forum rules - please read before posting.

Adding Reference Manager to References On Awake

Hello. I'm wondering if there's a way to automatically add a custom AC Reference Manager to the References.asset file in the Resources folder, On void Awake(), during Runtime. Say for example, to the Variables Manager slot. Custom AC Variable Reference Manager file name = "CustomVMgr".

For a normal object, it would look something like this:

public GameObject example1;

void Awake()
            {
                example1 = GameObject.Find ("CustomVMgr");
            }

But, after adding the script below to ManagerPackage.cs, I get "error CS0118: 'VariablesManager' is a type but is used like a variable". Is there a different way to call the Custom Variable Manager?

public VariablesManager variablesManager;

void Awake()
            {
                VariablesManager = GameObject.Find ("CustomVMgr");
            }

Comments

  • It seems using "public class References : ScriptableObject" is a bit different than using "MonoBehaviour". I don't believe an "On Awake" can be called in a ScriptableObject, "private void OnEnable()" can.

    "VariablesManager = GameObject.Find ("CustomVMgr");" won't work here either, since this applies to objects already in a scene. I'm trying to figure out if there's another way, specifically for ScriptableObjects.

    You don't need to go too deep on this one, maybe I can figure it out.

  • Both References and Managers are ScriptableObjects - they need to be accessible from any scene. As you've found, GameObject.Find only relates to scene objects.

    AC's References asset stores direct references to AC's Managers - you can see them assigned if you view its Inspector. The References asset itself is found by placing it in a Resources folder, and then using Resources.Load to locate it.

    Rather than modifying AC's core to reference a custom Manager class/asset, I'd recommend instead attaching a custom MonoBehaviour scipt to an AC object that survives scene changes - for example, the Player prefab, the PersistentEngine prefab, or a custom EventSystem prefab. From here, you can create a direct reference to an asset file should you want to - but either way, the custom script will be available across all your scenes.

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.