Mesh colliders inside an imported fbx file

Hello everyone,

I am using an asset from Unity to make some schools of fish. It works, using DrawMeshInstances, I can draw thousands of them, without any pain but for the CPU…

Now, I would like to add colliders to them. There is a box I checked which is “Generate colliders” when you’re clicking on the import model : Import Settings.

Then what I would like to do is just take the mesh contained in this model, named cruscarp, to continue using it as a parameter of DrawMeshInstanced, but will colliders enabled, that doesn’t work. Any idea to do this? Is that possible at least ?

Thanks

I don’t think that is possible.
Colliders are attached to GameObjects.
With GPU instancing, there are no GameObjects…

1 Like

Thanks for agreeing with my idea! It could have been cool though

I would also argue that using the “generate colliders” option might not be the best approach. If I recall, that generates specifically mesh colliders which are far less efficient, especially if you’re wanting thousands of something… would be much better to use a prefab with a box or other collider and instance it. As long as you’re using a shared material between them, your draw calls would still be fairly inconsequential, though not instanced.

Edit: I guess for something like “fish” that’s not static… you’d not benefit from static batching.

It looks like @Arowx did it for CubeMark, maybe he could give some pointers.

That was what I was doing first. But with thousands of items it was getting really slow, that’s why I played around with DrawMeshInstance… But I guess that I can’t have both, instancing that way to improve performances and getting the collisions.

I still can use gameobjects to try out the collisions with a decent number of tishes, thank you.

I just used game objects with or without colliders.

Although the way to think of it would be to use a set of colliders in the physics layer that would only be instanced or enabled within proximity to other colliders.

e.g. collision is only relevant when objects get within range of each other (Hint Hint UT).

Have you also tried the particle system as this has the potential for higher object counts and collisions.

1 Like

That was my next thought… even though you save on drawcalls, with thousands of objects the physics system would get overwhelmed if everything had a collider.

You can also use the instanced shader option, as this should do what drawmeshinstance does only with the overhead of a GameObject.

Really you should check out the recent keynote boids demo and hold on for the Multi-threaded transform/job system working it’s way from R&D into Unity.

goto 1h 8m for demo

I’m not sure when it’s due but it will make any games that use lots of entities way faster.

2 Likes

Thanks guys!

It’s true that particle systems could work, but I was curious to try out this way with instancing…

I tried out with the instanced shader, it works, but unfortunately it’s providing low FPS…
For example with thousands of fish it will be horrible if you need to instantiate these thousands of GameObjects right? :confused:

The new feature we can see in this video looks really interesting though!!

Something to think about is do you need physics collision or could you write your own proximity/collision system. If your fish shoal then they probably can be mimicked by one or more sphere colliders.

Also for behavioural movement you often need to use sphere casts to check ahead to avoid obstacles, if you need to do this then you can also use this to check for collisions.