[ad_1]
I am attempting to make the UI a part of a listing system which is able to contain the flexibility to maneuver gadgets from one slot to a different, animating the merchandise sprite going from one slot to the opposite.
Merchandise slot prefabs initially had a UI Picture element whose sprite property I used to show the merchandise. A difficulty I had with that’s that when shifting gadgets from one slot to a different, the sprite would both seem on high or behind different gadgets’ sprites relying on (I assume) the hierarchy order of the slots to which they belong.
I attempted trying round into how I might dynamically modify UI Picture or sprite render precedence, however options I discovered would both contain:
-
Utilizing a SpriteRenderer, which does not appear to be what UI Picture use, which means I’ve so as to add one within the prefab, and if I try this I would as effectively cast off UI Photographs within the first place and completely use them -> This does not work, and it appears that evidently SpriteRenderers aren’t made to work in a Canvas? From what I’ve tried, it looks like the RectTransform utilized by Photographs and Rework utilized by the SpriteRenderer do not use the identical coordinate system: if I give the identical place to each, they would seem somewhere else, and the sprite would probably be wayyy offscreen, except I as a substitute give it the identical coordinates as one other object seen within the scene.
-
Utilizing SortingGroup and sorting layers, which does not appear to work both for UI Photographs.
-
Modifying the render order by modifying the order of objects within the hierarchy. This final one would I assume works, however really feel kinda botchey and I can not think about that counting on hierarchy order for drawing order could not result in points additional down the road. Since at the moment every picture is at the moment a toddler of an merchandise slot gameobject, I can already see that it could seemingly additionally reorder the merchandise slots themselves in my GridLayoutGroup, which might require additional botching or rethinking every part to repair.
-
Utilizing a number of canvases in order that one can provide them totally different render precedence. I am undecided how it could go precisely, possibly two of the identical dimension layered one and briefly shifting merchandise slots from one canvas to the opposite at some point of the sprite’s motion? However this additionally really feel very botchy.
I’ll finally settle in for the hierarchy order technique, however I really feel like there is no such thing as a method there is not a greater resolution for this, except that’s my inexperience talking and that resolution is definitely good.
My query is that this: Whereas not asking for a “greatest” resolution, what could be one correct technique to obtain this?
I’m conscious the formulation is kinda loaded, and possibly “do it by altering hierarchy order” might be a correct resolution.
The model of Unity getting used is 2021.2.2f1. If one thing is unclear, I can present extra data or reformulate.
[ad_2]