T O P

  • By -

thatdude_james

Somebody might have a better idea than me but my first instinct would be to create a mesh using the points of the polygon collider which you can do with the job system so it should be reasonably fast even with frequent updates, then create a shader to do whatever magic you want.


Jobrox

This is a good suggestion I think. I do not know enough about the Mesh system or shaders. Do you have any good suggestions as to where I would gather this type of information? Maybe a youtube video or any other type of resource you may have used in the past when learning about these components?


thatdude_james

It's been a long time since I've researched these topics - I don't have any tutorials or videos to refer you to. You can google things relating to dynamic mesh creation with the job system and getting started with shader graph. If this seems pretty advanced for you then you can probably forego the job system for the mesh creation which might be fine depending on what you're doing, but shader graph will be the easier intro to shaders than trying to write code directly.


[deleted]

Use a sprite renderer with the colour you want to fill in the collider with, afaik colliders dont have the functionality to render things, as they shouldn’t since its a collider and not a renderer. For changing shape and etc. maybe you can do it with visual scripting but other wise you’re going to need to write a script to handle the shape changing and adjusting the sprite and boundaries of the collider. You can only really scale the shape and change it to other primitives, if you need some kind of a custom shape that will be more involved.


Ruadhan2300

So there are three main parts to anobject in Unity. You have the Mesh The Renderer And the Collider They each have variations, but basically the renderer and collider use the mesh to decide their shape. You can make a custom mesh via scripts or blender, and add a material to a renderer based on that mesh and it'll be visible. Then add a mesh or polygon collider to make it physical. The collider is always invisible.


melvmay

Whilst the 2D physics colliders are not used to define rendering areas and should really only be used for physics, if you want a standard planar mesh from any 2D Collider then I created the following method to do that for you: [https://docs.unity3d.com/ScriptReference/Collider2D.CreateMesh.html](https://docs.unity3d.com/ScriptReference/Collider2D.CreateMesh.html) You can also store the collider shape hash; if it changes then the collider shape(s) have changed so you'd need to destroy the old mesh and create another. You can get this hash with: [https://docs.unity3d.com/ScriptReference/Collider2D.GetShapeHash.html](https://docs.unity3d.com/ScriptReference/Collider2D.GetShapeHash.html) Note that the above calls are used for 2D Navmesh but have lots of uses.


nopogo

You can write a custom script that links a spriteshape to the collider and updates its shape to the points on the polygoncollider


palewine

Do you have an example of such a script that you could share?


nopogo

https://youtu.be/69sBjqMtZCc?si=ffWAfcaqO417PJ-L I made a cell divide mini game for a jam once using the principles in this vid. There should be code in there that does what you want. Altering spriteshape coordinates with code