I’m creating Inventory system. When i drag object around if it is not the last sibling it will be rendered under the other slots in the inventory.
Because I’m using Grind Layout to place the slots around i cant change the slot order in hierarchy (it will move it to be last slot). I tried adding a canvas component and check override sorting but then i cant interact with it move it around and click on buttons.
is there a way of changing rendering UI order without changing hierarchy?
For UI the Canvas Component is the only way. Your solution does work it’s just that you need to add a GraphicRaycast component to your transform in order to interact with it.
Hey @uri2563, I just had to figure this out as well.
To do this you need to:
- Add an Event Trigger component to your prefab (or just your GameObject) that you want to be set as the last sibling
- Click Add New Event Type and choose Pointer Down
- Click the + (Plus) button in the bottom right corner of your new event type to add a new event handler
- Drag the prefab into the slot where it says None (Object)
- In the dropdown that now says ‘No Function’, find and mouse over RectTransform and then SetAsLastSibling()
Now, the game object is listening for the PointerDown event and when that is triggered, it will find the RectTransform you set, and fire the SetAsLastSibling method.
Now that item is in front of all the others!
Try playing with the other event triggers. You may find something that works even better than this!