Hi there!
I am using Unity 2019.3.0f6 and Adventure Creator 1.70.1
I am trying to build menus that are controlled by custom scripts (i.e., setting the texts myself, not using AC's system because I want to use TextMeshPro). So I created a bunch of menus and am basically just using TurnOn() and TurnOff(), which works fine!
AC.PlayerMenus.GetMenuWithName("Inventory").TurnOff();
I am using Prefabs for the menus. But when I try to set the texts it does not work. Behavior is weird, sometimes I write a change and it doesn't show, but when I restart the game the text is suddenly set to the supposed values. Here's how I am trying to set the text:
itemDisplay = AC.PlayerMenus.GetMenuWithName("Inventory").canvas.GetComponentInChildren();
itemDisplay.SetText("hi");
It works like a charm when I do it like this, but I would like to avoid GameObject.Find()
itemDisplay = GameObject.Find("InventoryUI").GetComponentInChildren();
itemDisplay.SetText("hi");
So my guess is that AC.PlayerMenus gives me the prefab of my menu, not the instance? I also tried AC.KickStarter.MenuManager.GetMenuWithID(), which resulted in equal results.
-> How can I get the currently used instance of a menu via AC? <-
Thank you for creating this awesome asset!
Jens
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
I just saw that the markdown hides the type specifier of GetComponentInChildren - but there is one! :-)
This should be true when accessing MenuManager, but not when accessing PlayerMenus. However, you need to access the Menu's RuntimeCanvas property - not canvas, which is indeed the Canvas prefab. I shall look to make this distinction more obvious.
AC supports TextMeshPro - just define TextMeshProIsPresent as a Scripting Define Symbol. See the Manual's "Supported third-party assets" chapter for more.
Hi Chris,
thank you so much - that's great. I thought there was no TextMeshPro support because I had researched it and only found posts on this forum where it was not yet there - in one you said you might do it some day. Glad that it's here! Maybe it would be a good idea to make it a bit easier to find :-)
Best,
Jens
It's all in the Manual.