Forum rules - please read before posting.

Is there a way to make polygoncollider2D fit in the same shape as the 2D image/sprite ?

I basically have multiple 2D character images with transparent backgrounds and I want the collider to be in the same shape as their body so that the Hotspot hover stuff works perfectly and only when you are hovering over any part of character's body.

Doing it manually with the edit is very time consuming to outline the character so I'm wondering if there's a functionality or a better method that helps with that? Even if its by code, I just want to make sure that the hotspot only works when I hit the character's body.

Should I be combining hotspot with Raycaster? If so then can you give me an example of that. Thanks!


  • Just to be clear, Sprite Renderer works with polygoncollider but when it comes to UI image then you have to manually adjust the collider, so just wondering if AC has an easier way to handle something like that when it comes to Hotspot.

  • If you check "Generate Physics Shape" in a sprite asset's Inspector, attaching a PolygonCollider2D component to it in the scene should form an accurate shape around it.

    Are these images being animated, so that the collider needs to be animated / change shape?

    You mention "UI image", but only in your second post - are these sprites for characters in the scene, or part of a UI menu? If you can share images to show the issue, that'll help clarify the situation.

  • @ChrisIceBox Apologies for the late reply.

    To clarify, I'm using UI Image and would like to have a polygon collider shape the ui image. Sprite renderer works automatically as soon as I attached a polygon collider but what about the UI Image?

    Images will be a static image, so it won't be animated. In my 2D scene, I have stuff like clock attached to the wall etc that I want to be able to hover over and see the label using hotspot. I mean I could use 2D Box collider and just make a square collider but I would like the collider to be in exact shape of the image.

    Hmm might have to switch to sprite renderer instead.

  • A Polygon Collider 2D will re-shape itself automatically to fit the sprite when attached to a Sprite Renderer, but not for an Image component. In this case, however, you can still edit its vertices to reshape it manually.

    A Polygon Collider 2D is not used by Unity UI to affect a Button's "clickabe area", however. If you're looking to have this shape determine this, best to move it out of the UI and have it be a regular Hotspot / Sprite Renderer.

  • Yeahh I think its better to just stick with Sprite Renderer instead of UI Image. Manually adjusting each poly collider for so many ui images just seems like it would take a lot of time.

    Besides, I think I read some forums saying that using ui images is probably not the best idea anyways for ingame objects etc.

    Thanks for the help anyways. Cheers

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.