Forum rules - please read before posting.

Changing prefab in menu from AC Script

edited October 2020 in Technical Q&A

We have two AC Menus: StationMap and RoadMap.
It's our map in game. We call different map depending on location. Is it possible to change Linked Canvas Prefab in Runtime. Because the prefab is the only thing these two ac menus differs from each other. It would be great not to multiply these menus but make one and change prefab from script.
Now we change them using Menu:Change state command


  • You would have to update the linked prefab and re-initialise the UI:

    PlayerMenus.GetMenuWithName ("StationMap").PrefabCanvas = myNewPrefab;
    PlayerMenus.GetMenuWithName ("StationMap").LoadUnityUI ();

    I don't recommend this approach, though, as elements are linked to prefab components via Constant ID. A Button in Prefab A, linked to a Button in the Menu would need to have the same ID as it's "brother" Button in Prefab B.

    A better approach may be to rely on one prefab, but parent each map section to a separate GameObject, and then use animation to show/hide the intended parent based on the scene. This could be done with e.g. an Integer parameter, and then controlled with the Object: Animate Action when the Menu turns on.

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.