#Modify collider per instance.

1 messages · Page 1 of 1 (latest)

sturdy jacinth
#

I`m trying to mofidy the collision filter of a instance of an entity but it is modifying for all new spawned entities too.

This is my code:


                clone.CollidesWith = 1U << 0 | 1U << 3 | 1U << 31;

                CharacterAspect.PhysicsCollider.ValueRW.Value.Value.SetCollisionFilter(clone);```

How to modify for this instance only?
#

I`m using rival character controller.

#

is force uniqye per Prefab and not per instance?

fluid terrace
#

you are baking entity

#

which will get unique collider

#

but all instantiated entities from it will get same collider

sturdy jacinth
#

Do i need to clone the collider on instantiation then?

fluid terrace
#

I guess

#

but isn't there any component to override filter?

#

There is for mass

#

I'd think there should be for something as simple as filter as well

sturdy jacinth
#

How do u override mass?

fluid terrace
#

it's a component

sturdy jacinth
#

It is on pre.44

#

But yeah, there is only for mass

#

clone.CollidesWith = 1U << 0 | 1U << 3 | 1U << 31 i need this when he is dead

#

What if i bake two "coliders"

#

one for dead and one for alive?

#

cloning the alive collider and adding the filters

#

i need this while Untargettable too

sturdy jacinth
#

It is hard to do simple things ...

sturdy jacinth
#

I fixed my game adding a dead component (IEnableableComponent) and changing CanCollideWithHit to
return !context.DeadLookup.IsComponentEnabled(hit.Entity);

but changing the collision flags is better i think

fluid terrace
#

you can just switch collider

#

from alive to dead

#

on death

sturdy jacinth
#

How?

#

SetComponentData?

fluid terrace
#

yeah

sturdy jacinth
#

Will it update the physics under the hood

fluid terrace
#

it is physics

#

physics world is rebuilt every tick

sturdy jacinth
#

the bounding volume hierarchy

#

what, this is really bad

fluid terrace
#

it collects all transforms and it's colliders and builds it

sturdy jacinth
#

wtf this is super slow

fluid terrace
#

you can swap colliders every tick, nothing will change

sturdy jacinth
#

I see, thank you

fluid terrace
#

this is stateless physics

sturdy jacinth
#

But i`m building a game for 3000 players (online)

#

mmorpg

fluid terrace
#

rip

sturdy jacinth
#

maybe rebuilding the collider of 3000 players each tick is bad

fluid terrace
#

Rule of thumb: don't make MMOs

#

😅

sturdy jacinth
#

I did 3 already

#

one of them with 1200 players on same map (single threaded)

#

i`m confident on this lol

#

and i benchmarked 3000 players already at 300 Mbps and 4 cores cpu only

fluid terrace
sturdy jacinth
#

but you can`t cull / disable then

#

when outside screen

fluid terrace
#

why not?

#

oh

sturdy jacinth
#

Because all is active

fluid terrace
#

well, I believe some games just don't even load parts of world where player isn't

#

my only MMO experience was with WoW

#

and they simply just cut world in chunks

dark vessel
sturdy jacinth
#

I think it should work

dark vessel
#

I was actually unaware until today that Force Unique didn't apply to instances of a prefab as well. I kinda get why that's the case, but I'm asking around to see if manually cloning the collider blob really is what we expect users to do

dark vessel
#

ok so, we're aware that this is a usability issue and we want to look into it (no promises, etc), but for the time being, manually cloning is what needs to be done

fluid terrace
#

and switch when needed

sturdy jacinth
#

How to switch ?

#

Do i need to remove one of them at runtime?

#

disable maybe? idk

fluid terrace
#

copy from dead prefab

#

paste to target

#

Collider on entities is just a blob asset reference

sturdy jacinth
#

I can close it at runtime and assign on die

#

OnDie =
if(!DieColliderAssetRef.IsCreated){
DieColliderAssetRef = OriginalCollider->Clone();
}

#

something like this

#

but then i need to dispose it later

sturdy jacinth
#
                {
                    creature.SwapCollider = CharacterAspect.PhysicsCollider.ValueRW.Value.Value.Clone();

                    CollisionFilter clone = creature.SwapCollider.Value.GetCollisionFilter();

                    clone.CollidesWith = 1U << 0 | 1U << 3 | 1U << 31;

                    creature.SwapCollider.Value.SetCollisionFilter(clone);
                }

                CharacterAspect.PhysicsCollider.ValueRW.Value = creature.SwapCollider;```
#

this code works

rapid wind
#

A conversation in general just reminded me of how i handle a case like this

#
    [UpdateAfter(typeof(EndColliderBakingSystem))]
    [WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
    public partial struct FracturableColliderConversionSystem : ISystem
    {
        private BlobAssetStore blobAssetStore;

        /// <inheritdoc/>
        public void OnCreate(ref SystemState state)
        {
            this.blobAssetStore = state.World.GetExistingSystemManaged<BakingSystem>().BlobAssetStore;
        }

        // TODO can't be burst compiled due to BlobAssetStore.TryAdd
        /// <inheritdoc/>
        public void OnUpdate(ref SystemState state)
        {
            foreach (var (fracturableState, physicsCategory, collider) in SystemAPI
                         .Query<RefRW<FracturableState>, RefRO<PhysicsCategoryBaking>, RefRO<PhysicsCollider>>().WithOptions(EntityQueryOptions.IncludePrefab))
            {
                var clone = collider.ValueRO.Value.Value.Clone();

                var filter = clone.Value.GetCollisionFilter();
                filter.BelongsTo = physicsCategory.ValueRO.FracturedFilter.Value;
                clone.Value.SetCollisionFilter(filter);

                this.blobAssetStore.TryAdd(ref clone);

                fracturableState.ValueRW.FracturedCollider = clone;
            }
        }
    }```
#

i generate a second collider during baking with a different filter I can swap between

sturdy jacinth
#

Does it do it per prefab or per instante (on a subscene?)

rapid wind
#

it will do it per instances but it uses blobstore to share them again

#

now that you mention it though, i could (and probably should) check if i've already done a clone

#

and early out and grab the existing one instead of relying on the store

sturdy jacinth
#

This code is exactly what i need. Can i use it?

rapid wind
#

of course

sturdy jacinth
#

@rapid wind do the blobAssetStore makes the clone unique somehow?

rapid wind
#

it does the opposite

#

it's making identical colliders into a shared reference

#

if you want them to be unique you need to pass in a custom guid

#

so it won't match with existing data

sturdy jacinth
#

I see

#

Thank you

abstract isle
dark vessel
# abstract isle I think official will need to make modify collider at runtime much more easier. ...

Storing colliders outside of the chunk (in this case; in blobs) means reducing the size your entities occupy in chunk and potentially reducing the amount of times you might have to load the collider in memory since multiple entities can share the same collider. All this typically means performance gains. You also have to remember that some colliders will be meshes, which can take a possibly large amount of space that varies from one collider to another

Disclaimer; I'm not necessarily an expert on this topic but this is my understanding

dreamy token
# dark vessel Storing colliders outside of the chunk (in this case; in blobs) means reducing t...

I can understand why collider data is stored in blobs, but it feels unnecessarily complicated to store collision filters in the same blob. A collision filter is 3 only integers and switching layers seems like a much more common use case than switching entire colliders. Personally, I would love to see CollisionFilter separated out into a non-blob IComponentData so that it can be edited more easily. Or at the very least, it would be great if the physics package supported something like CollisionFilterOverride as an optional IComponentData to improve the ux for these use cases.

dreamy token
#

Maybe it's just me, but I tend to avoid blobs. I find the API for constructing them quite confusing and I'm never sure if I'm disposing and deduplicating them correctly. I heard its coming eventually, but its also a pain to debug anything with blobs as they don't show up in the entity inspector. I have a lot of static data that probably should be in a blob, but I've put off converting them for the reasons above.

fluid terrace
#

Query over your own p filter override comp

#

although

#

Hold up

#

I maybe confusing things

#

Better check where filter is stored in physics world

sturdy jacinth
#

I think colliders should be a tagged union with only meshes stored on blob

dreamy token
sturdy jacinth
#

It is better to have tagged union outside blobs, It is faster, more cache friendly and easier to modify per collider

#

All colliders are super efficient

#

A box is 6 floats,
a sphere 4 floats,
a capsule something like this too

#

except mesh that can be stored on blob outside

dreamy token
#

well there is also polygon and terrain colliders which I assume would have to live in a blob

abstract isle
#

🤔 Primitive collider stores at IComponentData meanwhile complex collider stores at blob

dreamy token
#

Yeah, it feels like it would just make colliders harder to work with

abstract isle
#

👀 Actually what I think currently is lacking utility method to make this easier. Looks like changing collider at runtime u need to access until pointer level lol

dreamy token
solar sequoia
rapid wind
#

Baking system only exists during baking