Forum rules - please read before posting.

MenuManager does not contain Method if builded

edited February 2022 in Technical Q&A

Hello!
I dont know if this is a bug or intended and I'm just doing something wrong but I have following problem right now:
Right now I have two different crafting menus. One is the default AC crafting menu and one is a custom one. I need the "Result is automatic?"-Option in the default crafting menu as true and in my custom menu as false. The problem is that the true "Result is automatic?"-Option in the default crafting menu has an effect on the costum one, even if it is disabled. So I tried to fix that through script. I set the "Result is automatic?"-Option of the default crafting menu to false if I enter the scene with my costum menu and set it to true if I exit the scene. Following script is doing it:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC;

    public class Drag_n_Drop : MonoBehaviour
    {
        public AC.ActionListAsset correctOrderAction;

        public void OnEnable ()
        {
            AC.EventManager.OnCraftingSucceed += OnCraftingSucceed;
            AC.MenuCrafting element = (AC.MenuCrafting) AC.MenuManager.GetElementWithName("Crafting", "Crafting");
            element.autoCreate = false;
        }
        private void OnDisable () 
        { 
            AC.EventManager.OnCraftingSucceed -= OnCraftingSucceed;
            AC.MenuCrafting element = (AC.MenuCrafting) AC.MenuManager.GetElementWithName("Crafting", "Crafting");
            element.autoCreate = true;
        }
    }

This works fine in the game preview but as soon as I try to build the project to test it in the browser, I get an error:
'MenuManager' does not contain a definition for 'GetElementWithName'.
Am I missing something?

Thanks in advance!
Pluh

Comments

  • At runtime, Menus are transferred onto PlayerMenus - these are the ones you want to affect.

    Any change you make to the Menus stored inside MenuManager will affect the originals.

    You just need to replace your instances of:

    AC.MenuManager.GetElementWithName
    

    with:

    AC.PlayerMenus.GetElementWithName
    
  • Nice, thank you!
    The problem now is that I have to change my script when I'm testing in Unity to MenuManager and when I build the game to PlayerManus.
    Is there a simple way to tell Unity what code to execute while in the editor and while in the browser/builded game?

  • You can wrap #if UNITY_EDITOR around Editor-only code, but unless you want to modify the original Menu settings, you shouldn't have to in this case.

    So long as you're looking to work with the runtime Menus - whether its in the Editor or a build - reference them with PlayerMenus, not MenuManager.

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.