#Can I create a Compound Collider at Runtime?

1 messages · Page 1 of 1 (latest)

frosty mesa
#

I have seen that it is possible to create a Compound Collider when converting GameObjects to Entities in sub-scenes at editor time. You simply either mark your top-level GameObject to be converted as Static the old fashion way, or add the StaticOptimizeEntity component to the GameObject. This will cause a compound collider to be created if any children of the top-level entity have colliders.

My question is: is there a way to do this at runtime, or does it require me to have hand-placed objects in sub-scenes at edit time?

#

Example: A Forest has the StaticOptimizeEntity component on it. It is in a sub-scene with thousands of Tree children. Each Tree has a collider. During the conversion process into Entities, each Tree no longer has its own collider, and instead the Forest has a single Compound Collider.

#

However, if I attempt to spawn Tree children at runtime and add them to a Forest, no Compound Collider is ever made.

#

I am assuming this is because spawning anything at runtime means it is technically not static, even if I mark it as such and it never moves after I spawn it.

#

Is this correct?

loud wave
loud wave
#

Just, will make it way harder doing it unintended

#

Make your trees kinematic and they will get unparented automatically

frosty mesa
#

I am parenting the trees to the forest on purpose to make my compound collider.

I don't want to unparent them.

#

My goal is to have the forest build a compound collider. I am sorry if that was not clear.

loud wave
frosty mesa
#

Unity creates the compound collider for you. But I have only got it to work at edit time (converting a sub-scene in the editor before pressing play).

loud wave
#

well yes, because Baking is editor only

#

no runtime

frosty mesa
#

Yes, my original question was if this process of creating a compound collider is a Baking process

#

Or however you want to word it

#

I guess the new term is Baking

loud wave
#

well, it is done during baking, that's for sure

#

you could inspect physics shape baker

#

and try to reverse engineer it

#

but why can't you just go with kinematic separate colliders?

frosty mesa
#

Ok, thanks for the clarification.

#

It's a long story. Short answer is, the ability to dynamically spawn hundreds of thousands of trees that can be chopped down with procedural generation.

loud wave
#

how compound helps in this case? I feel like it's actually making it way worse

frosty mesa
#

Physics just can't handle that many individual static colliders currently.

loud wave
#

since you are stuck with generating specific shapes

frosty mesa
#

Oh the colliders are basic. Just capsules.

loud wave
#

I mean, you can't easily swap tree position and etc

#

besides

#

Physics is resuing same shape

#

unless you specify otherwise

frosty mesa
#

Correct. You'd have to try an example project to see for yourself.

#

The physics system just spends so much time when that many collider objects exist.

#

Even though they do use the same collider hash

loud wave
#

I didn't work with compound the way you did, but in my use case all colliders in compound were individuals

#

as in, I could distinguish which collider hit trigger

frosty mesa
#

Yeah, sounds like you didn't have hundreds of thousands then

loud wave
#

it's just tied into hierarchy

#

and is treated as one

frosty mesa
#

You'd have to see. The physics engine cannot handle hundreds of thousands of entities that each have a collider on them, even if they all reference the same one. You'd have to try it yourself.

#

When you bake them into complex colliders ahead of time, you reduce the number and it runs fine. Makes sense.

#

I was just hoping for a way to do it at runtime, even if it took some frames to do so.

#

Especially since I would like to sometimes remove a tree from the forest if someone wants to chop it down, etc.

#

But most of the time the forest is "static" and unchanging

#

And sometimes it changes. I will just need to figure something else out.

loud wave
#

That sounds like you want Kinematic after all, not static

#

have you tried baking your forest as kinematic instead?

frosty mesa
#

Trouble is I don't want to use baking at all

#

Baking a sub-scene ahead of time is not my goal.

loud wave
#

then in runtime you instantiate them

frosty mesa
#

The individual tree, yes

loud wave
#

for this you want kinematic

#

not static

frosty mesa
#

That is true, those are baked

loud wave
#

especially if you want interaction with them (chopping and etc)

frosty mesa
#

I doubt I can have hundreds of thousands of kinematic colliders, which is why I was experimenting with making compound colliders

#

I was going to deal with the problem of individual interaction after dealing with the problem of having them merely exist

loud wave
#

Optimizations could help

#

as in

#

disabling parts of world

#

if they are too far

#

for interaction

frosty mesa
#

Yes, I was just seeing how far I can push things without resorting to the common tricks

loud wave
#

just try kinematic

#

Unity physics is stateless anyway

frosty mesa
#

I know. I am wishing it was not every day. 😂

loud wave
#

as in, it rebuilds static world every tick (but I could be wrong on details, better ask folks who work more with it)

loud wave
#

if you can afford license