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.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
OnMenuAppear() correctly detects when the menu appears if that's useful to know!
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.
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:
Or to keep track of all active subtitle menus, hook into the OnMenuTurnOn / OnMenuTurnOff events:
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