#Changing the RenderFilterSettings.Layer at runtime does not take effect
1 messages · Page 1 of 1 (latest)
how are you changing it?
in the example, its the renderfilter.Layer that takes an int.
RenderFilterSettings are shared components, so I have to reapply back the same way.
I check using CollisionWorld.CheckBox() and set the filter to 1 << 16 and then previous value 1 << 15. CheckBox() returns true on 15 (previous value) and does not on 16 (new value), which means the layer hasn't changed behind the scenes, eventhough the Inspector shows the value was changed.
yeah this looks fine, just wnated to make sure you were actually updating the shared object
it's pretty painful to have to write the shared component to update the layer, we were looking at doing this a few months ago and decided to just handle this in the shader for what we wanted to do instead
so i never actually tested if changing the layer actually worked
looks like we might have dodged a bullet accientally
wait hang on, this layer has nothing to do with physics
this is a rendering only layer
took me a while to understand what was going on, until I used CheckBox() with different filter settings to see which value CheckBox was seeing when it does the physics check.
checkbox does not use this layer at all
oh?!
PhysicsCollider.Value.Value.GetCollisionFilter()
physics layers are stored in the physics collider
renderlayer is just for rendering
so its just a rendering layer value....
/// <summary> Describes which other objects an object can collide with. </summary>
[DebuggerDisplay("Group: {GroupIndex} BelongsTo: {BelongsTo} CollidesWith: {CollidesWith}")]
public struct CollisionFilter : IEquatable<CollisionFilter>
{
/// <summary> A bit mask describing which layers this object belongs to. </summary>
public uint BelongsTo;
/// <summary> A bit mask describing which layers this object can collide with. </summary>
public uint CollidesWith;
/// <summary>
/// An optional override for the bit mask checks. If the value in both objects is equal and
/// positive, the objects always collide. If the value in both objects is equal and negative, the
/// objects never collide.
/// </summary>
public int GroupIndex;```
this is what controls physics collisions
hmm I will look into this. So I need to modify the entity's collisionFilter?
this is helpful, let me look into this! much appreciate you sending me in the right direction
explanation of how the multiple fields work together
hmm, i dont see how I can change the "layer" the collider belongs to. do I assign a new collisionFilter to replace the entity's current filter? apologies, I'm still grasping at this.
is there a way to view the collisionfilter an entity has in the Inspector?
so yeah unfortunately, much to my disagreement, the collisionfilter is part of the physics blob
so you must clone the blob and update the layer (or bake an alternate blob and switch between them)
yeah it should be visible by default
im still using 2022.3.25
hmm i haven't looked on 2022.3 but i think it should still work
not using beta
if you don't clone or replace the blob, it will affect all colliders of the same type
super pain
good news, next unity 6 version should be out of beta 🙂
this is all I see under Physics Collider under Inspector:
are you still on entities 1.0.16?
i think the inspector was added in 1.1
i would suggest updating to 1.2 though, it's full released - no longer in prerelease
yeah it only appears on unity6 by default in package manager
or do i have to use beta 6000 version?
supposedly internal paperwork and blahblah
they haven't filed to get visible on the LTS
but it works fine and is fully supported on unity 2022.3
so yeah you'll have to add the version manually through package manager or just probably easier just change version in your manifest
im new to all this maneuverings within Unity, I'll have to read up on it
Packages/manifest.json
ahh
"com.unity.entities": "1.2.0",
"com.unity.entities.graphics": "1.2.0",
"com.unity.physics": "1.2.0",
yours will say 1.0.16
just change them to 1.2.0
ahh yes it does
anyway that'll get you the physics inspector
so you can actually see what the hell is going on
are these all of it:
com.unity.entities.graphics
com.unity.physics
there is netcode as well if you're using that
i have netcode on a different project, so maybe I'll do that there. my playground here is just for this
I only see these two entries that have 1.0.16 version, anything else you suggest I change?
unity 6 is so much better for like tiny minor things 😄
but yeah ah no need to update
i dont have an entry for com.unity.entities separately, is this ok? or should I add it?
nah it's fine
it's automatically being brought into your project through graphics/physics
and it'll be 1.2 because they depend on it
opening the project now
i was avoiding 1.2 because I thought I had to be a 6.0 beta
yeah LTS, package manager and internal politic things
this is what I see now. so it's now just a matter of changing the collisionfilter on Physics Collider at this point?
this confirms what I've tested that the renderlayer is changed to layer 15, but collisionfilter is still 16:
so I tried changing the "belongs to" to another value, and it wouldn't let me change it
do you know if changing this is an acceptable action at runtime?
you can change it
but as you wrote above all entities that have the same collider, share the same collider blob
so changing 1 of them will change all of them
you need to clone the collider first to ensure you only affect the 1 entity
yea for some reason, I can't change the value through the inspector. im trying to figure out how to change this in code as we speak
hmm, the physics collider doesnt seem to be a shared component.. is this how you understand it as well?
@leaden finch so I thought if I do GetComponentData<PhysicsCollider>(e) into a var, I effectively cloned it?
no
there's literally a method on physicscollider called .Clone
PhysicsCollider.Value.Value.Clone()
/// <summary>
/// This function clones the Collider and wraps it in a BlobAssetReference. The caller is
/// responsible for appropriately calling `Dispose` on the result.
/// Returned collider is guaranteed to be <see cref="Collider.IsUnique">unique</see>.
/// </summary>
///
/// <returns> A clone of the Collider wrapped in a BlobAssetReference. </returns>
public BlobAssetReference<Collider> Clone()```
alternatively it's a lot easier fi you know ahead of time that you're going to be having to do this
this threw me off since the GetComponentData returns the "value".
to instead just mark your collider as unique during baking
so you don't have to deal with cloning/managing it
💯
there was talks to move the filter out of the blob which i was very supportive of
but they decided not to do it for some reason
personally i'm waiting for 1.3 and i'll probably just fork and move it out of the blob myself because to me it's MUCH MUCH nicer
yea it would feel cleaner and clearer
the whole xx.value.value.yy is already messy
The .clone() returns a BlobAssetReference, which I then get the collisionFilter from, change it, but how do I reassing the blobasset as a new PhysicsCollider?
new PhysicsCollider {Value = newphysCollider}
i would suggest looking at this sample
it will show proper setup of changing the filter
yeah there's a pretty comprehensive sample suite now
I have to look at this whole physicsSample repo. there's lots here.
I've largely been fumbling through all this by loking at code alone
the process of marking a physicsCollider "unique", can I do it in the gameobject prefab via the inspector, or it has to be done completely through the baker Bake(authoring) ?
i think it can only be done through teh physicshape authoring atm
not hte built in boxcollider stuff
but i still use physics shape because its so much better
(accessed via adding samples in package manager)
oh then I can't do it since I'm using the builtin's