Heavy performance killing bug with physics

It appears this bug can reduce the framerate to 0fps! I’m using a physics handle for grabbing objects and throwing them. These objects consists of actors which have just simple box collisions that are welded together. So like ca 10 box actors welded together. Every time a object is grabbed again the framerate gets reduced while that object is physic simulated. First I have 90 fps, after the 30th grab I have like 10 fps. However, when the physics simulation is set off it jumps up to 90, when set on again back to 10fps.

To recreate:
At runtime spawn several box actors and put them perfect close together (It is a random constellation for me) attach weld all to the first actor. On input 1: Set that first actor to be physics simulated and grab it with a physics handle. (don’t forget the set target location every tick, I also set the rotation to 0 every tick since the physics handle rotation constraint does not work) On Input 2: release the actor, make a delay and set physics simulation off. At play use input 1 and input 2 several times and see the framerate dropping everytime. (I’m using no gravity on the box actors and make use of set impulse and add force after a object is released from grab. I’m also changing the collision type from vehicle to physics object and back again)

I have no idea what exactly is causing the framerate drop, maybe it even has nothing to do with physics handles nor welding collisions and it is a general physics bug.

Here is also that physics handle bugs report where I briefly mentioned this: https://answers.unrealengine.com/questions/423767/physics-handle-rotation-now-completely-broken.html Since I’m not sure if that is connected to physics handles and this is a heavy problem I made this a own post.

Hi ,

  • Does this occur in a clean, blank project with no additional content or is it limited to one project?
  • Has this occurred with any other actors or does it occur with the basic cube?
  • Can you show me a screenshot of your blueprint setup?

,

We touched on this briefly in the other post. Thought I’d post this here too just to make sure we had full coverage.
It sounds like this related to an issue we’ve recently fixed (but that won’t be released until 4.13).

The fix is pretty simple though. If you’re using the source version, go to
Engine\Source\Runtime\Engine\Private\PhysicsEngine\BodyInstance.cpp, at around line 2037 (in FBodyInstance::Weld).

Modify the function like so:

bool FBodyInstance::Weld(FBodyInstance* TheirBody, const FTransform& TheirTM)
{
	check(IsInGameThread());
	check(TheirBody);
	if (TheirBody->BodySetup.IsValid() == false)	//attach actor can be called before body has been initialized. In this case just return false
	{
		return false;
	}

    if (TheirBody->WeldParent == this) // The body is already welded to this component. Do nothing.
    {
        return false;
    }

The important bit is that second if statement (the rest should already be present).

Let me know if that resolves your frame rate issue.

Thanks,
Jon N.

Thanks, I have not done anything with the source before so I rather keep working with the bug for now. If it takes too long with the 4.13 release I then try that with changing the source.

Looks like the fix created a new bug in 4.13: Ghost collision bug - World Creation - Unreal Engine Forums