Forum rules - please read before posting.

Using constant ID duplicates to force alternate menu elements to be used

Hi!

I have my InteractionUI menu (Unity UI prefab which has look at/use/talk to... options)
Interaction UI prefab looks something like this:

InteractionUI
-grid (has constant id)
- LookButton (has cid)
- UseButton (has cid)
- TalkButton (has cid)

InteractionUI canvas is slotted as "Linked Canvas" for interaction menu, and Buttons are slotted as interaction elements for the menu.

Now, in some situations, I want my InteractionUI to be bigger, to scale up to 2, and
I have to realign some elements, I basically need another look with same functionality.
So I have duplicated grid element and made modifications to my new grid element, so now I have this:

InteractionUI
-grid (has constant id)
- LookButton (has cid)
- UseButton (has cid)
- TalkButton (has cid)
-grid_version2
- LookButton (has cid)
- UseButton (has cid)
- TalkButton (has cid)

Now I want to switch between these two looks (grids) of my interaction UI in runtime when needed.

I found out that if I disable one of the grids and leave the other one enabled, and I duplicate IDs between grids, (set manual constant id for all the buttons and copy them so all the buttons have the same constant ids) AC automaticaly picks up grid elements which are available, so I toggle between visual styles (grid and grid_version2) by just enabling/disabling root elements.

This is currently working, but I am concerned because, as I understod, AC does not want duplicate IDs by design and tries to change them whenever possible thus breaking my solution each time I restart Unity, reloading scene or... not sure what are the exact cases when AC fixes duplicate IDs...

My question is, could this be viable solution, is there a way to turn off duplicate ID "autocorrect" in AC?
Does implementing "do not override duplicate" checkbox for Constant ID script makes sense? So we could check/uncheck this on particular object level?

And do you maybe have better solution for this problem, when you want to switch UI look at runtime?

Thank you!

Joakim

Comments

  • AC Constant IDs are always used to map objects 1:1 - having multiples objects share the same ID introduces the issue of the wrong object becoming mapped to. The "autocorrect" system is there to fix such issues, and I don't plan to remove this or make it optional.

    However, you can always change an element's linked UI component at runtime. For example, to change a MenuInteraction element's linked Button component:

    (AC.PlayerMenus.GetElementWithName ("Interaction", "Use") as MenuInteraction).uiButton = myNewButton;
    

    Where "Interaction" is the name of the AC menu, and "Use" is the name of the MenuInteraction element.

    That said, have you considered animating the size changes instead? With one set of components, you could try attaching an Animator and switching between two animations that each set their layouts/sizes to the large/small variants.

  • I have just realized that I actualy only need to adjust scale for my UI to make it bigger, no need for some more complex layout changes afterall, so I just attached script which changes scale of the root object when needed and this works!

    Using Animator sounds great for some more complex UI layout changes, and thank you for the info on swapping linked UI component at runtime! This could come in handy.

    Thanks for your quick answer!

    Cheers!

    Joakim

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.