Download

Setting MassInKg During Runtime?

I have a static mesh component (Motor) that is a child of, and is welded to a physics simulated static mesh component (Frame). I need to set the mass of the Motor component in a constructor or during runtime.

Example:

The Set Mass Override in Kg method is the only functionality I can find available to do anything of the sort. However, it sets the mass of the entire physics body - the body formed by the Frame and its welded child component Motor - even if the target is set to Motor. The solution, I would assume, would be to uncheck Auto Weld on the Motor then, in a constructor, set the mass using Set Mass Override in Kg and weld it to the Frame manually. Unfortunately, the results from doing so are weird and don’t really seam to work. The components appear to be welded but the physics are off and completely unpredictable, unlike when they are welded automatically.

So am I doing something wrong? Is there additional setup involved with welding manually? Is there a better way of going about this? I’m coming from unity and as an unreal user of about a month, any thoughts or advice would be helpful.

Thank you!

didn’t read much except the title.
Just chiming in to say that last I checked massinKG did absolutely nothing with default physx.
a ball of 1000kg will fall the same and bounce the same as one of .001kg
I doubt things have changed, but maybe test it out with basics - such as the 2 balls actually reacting differently in regards to restitution.

Interesting. From what I can tell, it definitely doesn’t do nothing. At least when setting its value in the editor. Setting it through code seams to lead to all sorts of weirdness including sometimes doing absolutely nothing at all.

It’s involved, but you can build the engine from source with the latest physx version and correct this too.
Not sure why -legal?- epic hasn’t bothered updating their broken distro in a long while.

On that note. If you don’t want to fix stuff (can’t blame you, the reason we use an engine in the first place is we shouldn’t have to do stuff like this, right? Not, not according to Epic :stuck_out_tongue_winking_eye:)…
Try the Chaos build.

And if it doesn’t work as intended, supposedly (rumor and hearsay!), the epic team might actually care enough to fix it.

They have been trying to say that their concoction is going to be much better than physx.
In my testing of it, this is anything but true…

The only hope for it is that they actually bother addressing customer feedback…

1 Like

Thanks for the info :slightly_smiling_face:

As it turns out, the Set Mass Override in Kg method does and works exactly as it should. Bravo, Epic Team :clap:

And, the solution I mentioned actually works :smiley: The difficulty comes from my particular use case and ensuring that all components are set up so as to allow proper welding.

In short, if you have a similar problem, just make sure that the physics simulation on the component(s) to be welded is properly set up and that you save all the welding for after you change anything that could effect its physics.

…seams pretty obvious now that I thing about it :neutral_face:

1 Like

So the override works, but the manual BP entry does not (still) correct?
Or did you swap to Chaos before it worked?

Still using default PhysX.

The override works but only when all of the relevant physics, collision and welding parameters are set up properly. I do all of it through code because doing it manually in the BP can be extremely confusing:

Uncheck Simulate Physics so that I can enable Auto-Weld. Wait? I need physics! Re-enable it. Uh… Okay. Auto-weld is still enabled? So why couldn’t I enable it when physics was? What would even be the point of welding when there is no physics?

If physics isn’t enabled, properly set up and being simulated, setting MassInKg in the BP or with the override does absolutely nothing. That’s OK. That makes sense (mostly), but it would be nice if the engine gave me a little console message or something to inform me that the settings I have chosen are not all compatible.

It just seams to be this way through the whole thing: It’s extremely unintuitive. It can work, but getting it to is a nightmare.

This is a 100% accurate description of unreal engine… :roll_eyes:

Thanks for explaining. I’ll give it a try in CPP directly next time I open unreal…

1 Like