Forum rules - please read before posting.

Set UnityUI Prefab hierarchy list elements to sort by order found

I have a Notes system set up through the menu manager that uses a Unity UI prefab. Basically all the notes that the player can unlock are in a long list of hidden text elements that are defined as labels in the menu manager. When the player does something or goes somewhere that would enable a note to appear in the notebook, I have an action that makes the corresponding label visible.

Since the text elements are in a pre-defined order in the UI hierarchy, this means that if a player finds a note it will appear in this order - so the newest note found may not always appear at the bottom of the list depending on the order that the player plays the game. I'm looking to find a way to have the notes order to sort by order the player has found them.

I was planning on using Transform.SetAsLastSibling, but I'm having difficulty communicating with the menu prefab. I was hoping to use the "object send message" action and pass an integer to the notes menu, but since the notes menu is not open/enabled at this time it can't find the referenced gameObject.

Do you have any suggestions on how to go about this? There may also be a totally different way to accomplish this that I didn't think about. My coding skills are pretty weak, so I'm probably missing something obvious.

Thank you for the help!

Comments

  • edited November 4

    There may be more to it so far as your intent goes, but from your description it sounds like you could just use AC's Inventory system to handle this automatically.

    If you define your notes as Inventory items, you can place them in a separate Category to your regular Items, and then filter out that category in your Inventory menu. Your "Notes" menu can then list the notes within a separate InventoryBox element that only shows Items in the Notes category. Their display order will then be shown in the order they were added using the Inventory: Add or remove Action.

  • Hmm interesting idea! I'm a little hesitant to mess with the inventory system as a whole, however, since my game launches in 2 weeks. I also have it set up where the game can read progress through the notes by checking their visibility in the menu. If I did an inventory system I could check if the note is "in the inventory", but since I have roughly 100 notes and also 100 checklist items already in place it would be a bit of an overhaul.

    I was just thinking, what if I attach a script to each note text item within the note menu prefab that runs when the note is enabled telling it to set as last sibling? I'll test it today.

  • Ok nevermind. That doesn't work because the scripts are still being called simultaneously when the menu opens the first time, hence having the items showing up in their pre-defined order again. Plus there would be issues with loading different save files and loading the order the player unlocked notes within each playthrough.

  • Yes, in general I'd advise against using an object's position in the Hierarchy to control anything as it can be unreliable.

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.