Hello Guest

Author Topic: Sprite selection by order in layer  (Read 4239 times)

TOO DX

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Sprite selection by order in layer
« on: October 24, 2015, 01:27:36 am »
In the scene view, when I click on an area with a stack of sprites, I don't always get the sprite with the highest order in layer. I'd like to know why this is, and if there is any way around it.


Here I clicked the big blue guy's belly, but it selected the table behind him.

In most cases, a very large object will be selected (such as a background sprite) and clicking on other sprites will not change my selection to the smaller sprite, even though it has a higher order in layer.


Here I clicked the top right of the table behind the blue guy, but I got the long strip of floor behind it.

I am using a script that I run in edit mode which changes the SortingOrder of sprites in order to have them display correctly in my game's perspective. Could that be causing an issue?

Also, occasionally when trying to select a sprite that is behind a sprite but not being overlapped it (so it is within the front sprite's bounds) it will select the sprite in front. When selecting sprites in the scene editor, is it checking the sprite's bounds, the polygons the sprite is rendered on, or the actual opaque pixels of the sprite? Ideally, I'm looking for the latter. I want it so that when I click in the scene view, I select the object that owns the sprite of the pixel I can see under my mouse cursor.


Here I have the opposite problem, where I tried to click on the nuts, but got the guy passed out in front instead.

TOO DX

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sprite selection by order in layer
« Reply #1 on: October 26, 2015, 05:12:20 pm »
Alright, I was able to make some progress. If I move objects closer to the camera, then Unity will set their priority correctly. So, in my case, I also adjust the object's Z position very slightly based on their sort order.

Next is to solve clicking through sprites bounds. If anyone has a suggestion at where I should start looking, I would appreciate it. :D

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite selection by order in layer
« Reply #2 on: November 03, 2015, 01:22:44 pm »
Clicking through sprite bounds is a pain, the easiest thing you could do is add colliders and use raycasts to track clicks. That will work natively and since you're probably not using physics, will probably be the least intrusive way to do this.