How to change collision box for physics asset in runtime

I have skeletal mesh and need to change its collision(simple box collider) size in runtime. Collision box created in Physics Asset. How can I do that? Also is there any ways to detect actor size in meters(or similar units) to set proper collision scale in runtime, depending on all skeletal meshes in an actor (something like detecting bounding box size)?

2 Likes

Anyone? I’m also interested in changing aspects of the physics asset at runtime.

Hey there. I’m not sure if you can change the exact geometry of a physics asset at runtime, but you can do some tricks with the existing geometry. Most of them are not available in blueprints, though. In C++, a skeletal mesh has a “Bodies” array of FBodyInstance*. Each Body Instance has plenty of methods, e.g.

UpdateBodyScale(const FVector& InScale3D, bool bForceUpdate)

directly changes the scale of the shape in 3D, I believe it is what you need, but once again, it’s not exposed to blueprints and will hardly ever be.

I’ve tried this but it doesn’t seem to work even with force update set to true. The function returns true to say it’s been successful but there’s no difference in the game.

I also tried calling RecreatePhysicsState() after but it’s still not working, maybe there’s some trick I’m missing.

I know it’s a bit late, but for anyone interested, I’ve found a workaround for scaling bones, modifying physics and collisions correctly:

  1. make an extra bone for each part that can be scaled, these bones will have the rig information and will be children of the bones that we would like to scale, in my case:
  • tail_1

  • tail_1_scale (this will be the one that contains the rig information)

What we will do with these bones is to scale only the child bones and modify the parent ones.

  1. The first thing is to create an animation we would use to scale the bones, but instead of scaling them we are going to distance the bones from each other, without scaling them, just moving them, and we are going to scale only the bones with the subfix “_scale”.

2.5) If we don’t want to use animations, we will do it from the nodes “modify transform (bone)” from the anim blueprint, and we will modify the scale of the child bones “tail_1_scale”, and the offset of the parents with a copy of the same node.

After doing either of these two options, we will be able to verify that visually the engine does change the length and scale of the bones when the animation is active, but we need much more for that displacement and scale to serve us in other scenarios.

  1. In the Physics Asset, we are only going to add bodies in the parent bones “tail_1”, in my case I have added a small sphere at the beginning of the bone with the mass set to automatic.

For the next step we will need a function written in C ++ that allows us to modify the position of the constraints in frame 2 (the position of the second body relative to the constraint). I think Unreal 5 has a blueprint function for that.

  1. In the script that is modifying the scale, we are going to multiply the position of the next bone from frame 2 of the constraint, in my case the next bone is “tail_2”, by the scale of the bone that we are scaling, thus adding the offset that the parent scale would have added.

  2. For the collisions we can create them procedurally with add component, or manually if you prefer, we can store these collisions in a map, with the bone name as key, and a structure with an array with the respective collisions as value, in this way, once the collision is created, we will have to attach it to the parent bone “tail_1” with the node “attachComponentToComponent” and checking “weld bodies” it is important that the collisions created are simulating physics, and have an appropriate collision profile, each time we modify these bones, we can call a function that updates the shape or quantity of the collisions. This will even distribute the weight correctly.

Note: in my case I bought a plugin that has saved me a lot of headaches called “collision disabler” created by Tomasz Klin, which allows me to add collisions while keeping the possibility that the other parts of the skeletal mesh keep the collisions with them, if you use this plugin make sure to disable collisions between adjoining bodies before attaching it with the bones.

Have you figture out why the RecreatePhysicsState api doesn’t work? I met the same problem recently

So difficult to implement it. Have you tried to implement a plugin for these? Plugin is more clear

sounds right, i will write a demo to verify that