why sorting layers not working?
hello. i am having a problem about sorting layer. i totally get how it works.... its just that when i do it, it doesnot work. i have searched all questions thread and found few ways. but when i apply to my project it doesnt work.
i have a sets of gameobjects in 1 same sorting layer. by changing the sorting order it should have work. but it did not. based on the unity tutorial it should have worked. all the objects have sprite renderer. also all of them are under 1 same parent.
so i tried with the changing z value option.. still doesnt work.
i was using setting gameobject as last sibling originally, but a situation calls for me not to use it. ( by setting the gameobject as last siblings does bring the gameobject on top of the other ).
pls help me .. did i miss anything?
i even tried to create new project with just a bunch of image to test all the ways but result are the same.
thank you for your time.
Answer by renomabum · Feb 14, 2019 at 04:04 PM
Hi.. so after searching multiple threads , videos etc.. and not found the answer. I finally figured out a way around to achieve my goal.
i attached my gameobject with canvas component. ( dont forget to add graphic raycaster component aswell if you want your object to interact with pointer events.. eg. ipointerclick, ipointerenter etc..).
so, you can set your sorting order from inspector or via script.
however, you can only set the sorting layer of the top most parent in the hierarchy.
this means if the parent and child both have canvas component, i'm only able to set the sorting layer of the parent.
i tried setting the children's sorting layer to a different sorting layer than the parent via script, but when i enter play mode the sorting layer of the children still follows its parent's.
so with this i can only change the layer order of the children.
this is the codes i used for this.
gameObject.GetComponent<Canvas>().sortingLayerName = "SortingLayerNameThatYouAlreadycreatedInTagsAndLayers";// use this to set sorting layer
gameObject.GetComponent<Canvas>().sortingOrder = AnyInteger; // use this to set the order within the sorting layer
In Conclusion, This Question Is Still Not Answered. And I will still wait for answer or any explaination regarding my issue here. Because even after i achieve what i need, i still need to figure out why the previous method that i mentioned in the question did not work.
BTW, this is the unity tutorial video that i followed exactly ( created new project just to test out ) and did not achieve same results.
https://www.youtube.com/watch?v=ZzcyREamMUo
Cheers
Answer by unity_0GlwZ4j_Ggr0lA · Nov 01, 2020 at 06:11 AM
I had a similar issue but I found this article in the manual to be helpful:
https://docs.unity3d.com/Manual/2DSorting.html
It turns out I was using sprites that were rendered with differnt materials. This causes the problem.
BREH, I'VE BEEN SEARCHING FOR THE ANSWER FOR THE WHOLE DAY, AND U JUST SOLVED THAT WITH JUST A SIMPLE ANSWER, thanks, I just need to remove the material and everything worked again, if the game I'm working on beco$$anonymous$$g a success, I'll reward u later XD
Answer by Greywize · Feb 01 at 07:39 PM
To anyone running into this issue in the future, be aware of the order your sorting layers are in your project settings. The order matters!
Your answer
Follow this Question
Related Questions
Sprite sorting order, background behind middleground but in front of foreground 1 Answer
Sorting Layer Overwriting not works 0 Answers
line renderer sorting order? 1 Answer
How i make the panels appear above the buttons??? 1 Answer
Stop Gun clipping into objects in Google VR (Cardboard) FPS game 1 Answer