Forum rules - please read before posting.

How to disable menu elements/buttons via script?

Sorry for this probably trivial question, but I just can't figure out how to disable the functionality of AC menu buttons by script.

I tried a lot of things, like

AC.MenuButton SomeButton = PlayerMenus.GetElementWithName ("Main Menu", "Some Button") as SomeButton;

SomeButton.SetUIInteractableState (false);

etc...

Any hint would be greatly appreciated.
Thanks!

Jan

Comments

  • Is the Menu being rendered with Unity UI or AC, and what is it you're trying to do, exactly? Disable the interactivity, or the visibility?

    Calling SetUIInteractableState should work if the Menu uses Unity UI (see the Scripting Guide), but not for AC. Bear in mind that this'll be set automatically when entering/exiting Cutscene mode, however.

    Scripting with any menu is generally much easier when using Unity UI, so convert your menu to that if you haven't already. If you then attach a Canvas Group component to your Button, you can control its interactivity by setting the Canvas Group's Interactable field. Since AC won't be controlling this, there won't be a conflict and you can manipulate it to override AC whenever you need to.

    To get the Canvas object of a Menu:

    Canvas myCanvas = PlayerMenus.GetMenuWithName ("Main Menu").canvas;
    
  • Just wanted to let you know that your idea with CanvasGroup worked like a charm. Stupid me, that this didn't come to my mind myself. But thank you 1000x!

  • Hi, I'd like to use this function but have a few questions.

    If I get the Canvas object of a Menu with :
    Canvas myCanvas = PlayerMenus.GetMenuWithName ("menuName").canvas;

    That means I can use myCanvas.SetUIInteractableState = false/true??

    If I want to get specifically the menu element, would it be:
    Canvas myCanvas = PlayerMenus.GetElementWithName("menuName", "menuElementName").canvas;??

    And to be able to use it, do I have to create a script with those lines, add the script to the menu canvas component and then use the Object: Call event Action, and create an event that refers to the canvas and calls the appropriate function in the component?

    Now, as an alternative I found in the scripting guide, the function AC.MenuElement.isClickable, does it work similarly to SetUIInteractableState? If this is something you'd recommend, then would you kindly advise on how to create a custom action to change menu elements to clickable and non clickable?

    Thanks so much for your help!

  • edited September 2021

    What's the context? To disable all elements within your UI, or just one in particular?

    My above mention of accessing the Canvas was as a means to simplify the process by using a Canvas Group component's Interactable field. If you're dealing with the original issue of affecting only a particular Button element, you don't need to deal with "canvas" at all.

    To get a specific menu element, you can call:

    MenuElement myElement = PlayerMenus.GetElementWithName("menuName", "menuElementName");
    

    You then need to cast it to the appropriate subclass. In the case of a Button element:

    MenuButton myButton = (MenuButton) myElement;
    

    From here, you can then call SetUIInteractableState:

    myButton.SetUIInteractableState (true/false);
    
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.