Forum rules - please read before posting.

Anyway to reference objects created by AC.SceneManager.AddPrefab ?

I am using AC.SceneManager.AddPrefab to create a Marker2D, and wish to reference the added marker in some actions. Is that possible either in the ActionList window or in Actions written by script (https://adventurecreator.org/tutorials/writing-interaction-through-script)?

Comments

  • For script, I am using
    Marker marker = AC.SceneManager.AddPrefab ("Navigation", "Marker2D", true, false, false).GetComponent<Marker>();

    It works in Unity Editor. But when I tried to build, it gives an error of
    AC.SceneManager' does not contain a definition for `AddPrefab'

    How may I solve this?
  • The AddPrefab method is not designed to be run at runtime - it's an Editor-only feature.

    If you're just trying to add in a Marker2D dynamically, just create a reference to the prefab in your script:

    public Marker marker2DPrefab;

    Then, when you want to instantiate it:

    GameObject newObject = GameObject.Instantiate (marker2DPrefab.gameObject);
    Marker myNewMarker = newObject.GetComponent <Marker>();
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.