I’m trying to simple change the CollisionFilter (in particular, the BelongsTo) of an entity with PhysicsShape at runtime. However I noticed that PhysicsShape doesn’t appear to be a component in and of itself, but rather just an authoring script that does a lot of things. As such I can’t make out how the source code of PhysicsShapeAuthoring is actually applying component data to an entity, and thus can’t figure out how I would do this at runtime.
The only component I can see that might be relevant is PhysicsCustomTags, but this just has a single value rather than the 2+ values I’d expect for collision data
The trouble with this method seems to be that it changes the collider for every entity that used it, as the collider itself is referenced by all instances of the entity prefab.
In my particular use case I have two teams which both share the same prefabs, and I’d like to be able to convert the prefab and then set the collisionfilter based on the team post-instantiation.
As far as I can tell I need to create a copy of the collider in the blob asset store with the different collision filter, and then select that, but it’s somewhat unclear exactly how to do this.
If I’m not mistaken, in the PhysicsShape component, you can enable “Force Unique” and that’ll make your colliders independent from each other. That way you can modify them individually when spawning them
I guess an optimisation in your case would be to not ForceUnique, but instead manually create one unique collider per team with the right material assigned. But I’m not currently sure how to create a Collider copy