Forum rules - please read before posting.

Menu check .IsOn() & .IsVisible() returning false when menu is on screen

AC Ver: 1.71.4
Unity Ver: 2019.2.4f1

Heya,

I'm trying to check when a menu is visible. I have a reference to the menu, but both .IsOn() and .IsVisible() are both returning false when its definitely visible on screen.

Here's the setup:

The menu is for the player subtitles, and it's using a Unity UI prefab as it's source.

In code I then do:

private void Start()
    {
        playerSubtitles = PlayerMenus.GetMenuWithName("SubtitlesPlayer");
        print(playerSubtitles.NumElements);
    }

(I put the .NumElements on there to check it's definitely getting something and it seems to be fine.)

In Update I'm then doing a simple check:

    private void Update()
    {
        print(playerSubtitles.IsOn() + " : " + playerSubtitles.IsVisible());
    }

Even when the menu is on screen the above continually returns false.

Comments

  • edited June 2020

    OnMenuAppear() correctly detects when the menu appears if that's useful to know!

  • edited June 2020

    With the help of the Discord, we've established it's to do with the "duplicate for each line" option.

    If true, the menu visibility isn't returned correctly.

    If false, the menu visibility is returned correctly.

    I understand the option is about duplicating the menu for speech lines - which I assume is the reason the setup I had above wasn't working properly.

    I'd love to know more about that option, and best practice how to check for if a menu is visible with it set to true. For now I've set it to false.

  • edited June 2020

    Yes - it's to do with the "duplicate" option.

    When enabled, AC will create a copy of the menu each time it's requested to be turned on. The one that appears on-screen is not the same as the one you're accessing through code with "GetMenuWithName" - which is the original.

    Since you're duplicating the menu, though, you need to work with a list/array, since this option allows for multiple of them to display at once.

    If you have a Speech class instance, you can get all Menus associated with it using:

    KickStarter.playerMenus.GetMenusAssignedToSpeech (speech);
    

    Or to keep track of all active subtitle menus, hook into the OnMenuTurnOn / OnMenuTurnOff events:

    using UnityEngine;
    using System.Collections.Generic;
    using AC;
    
    public class StoreSubtitleMenus : MonoBehaviour
    {
    
        private List<Menu> activeSubtitleMenus = new List<Menu>();
    
        private void OnEnable ()
        {
            EventManager.OnMenuTurnOn += OnMenuTurnOn;
            EventManager.OnMenuTurnOff += OnMenuTurnOff;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuTurnOn -= OnMenuTurnOn;
            EventManager.OnMenuTurnOff -= OnMenuTurnOff;
        }
    
        private void OnMenuTurnOn (Menu menu, bool isInstant)
        {
            if (menu.title == "Subtitles" && !activeSubtitleMenus.Contains (menu))
            {
                activeSubtitleMenus.Add (menu);
            }
        }
    
        private void OnMenuTurnOff (Menu menu, bool isInstant)
        {
            if (activeSubtitleMenus.Contains (menu))
            {
                activeSubtitleMenus.Add (menu);
            }
        }
    
    }
    
  • edited June 2020

    Thanks Chris that's really handy to know.

    In my case, because this is the player speaking I believe it makes sense that it shouldn't be duplicated - the player should only ever be saying one thing at any one time.

    As a bit of a feedback, it would be great to add a note to the scripting guide (or a little something in the manual) on entries like these which say if the menu is duplicated getting a reference to it is a bit different - https://adventurecreator.org/scripting-guide/class_a_c_1_1_player_menus.html#aead571ebcc7e25975f87e45900716909

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.