Problems with PhysicsConstraint in c++

Essentially my goal is to move/bend a mesh of a tree, especially the branches, when the tree hits the ground.
Therefore i want to make kind of a physical skeleton of the tree. But as the trees are generated procedurally, the skeleton needs to be generated procedurally too. So my plan was to spawn a bunch of cylinders, rotate and scale them according to the form of the tree, and connect them with PhysicsConstraintComponents. Now comes the confusing part: In a preview version of the engine, the cylinders spawned and connected at runtime perfectly well (although the physicsconstraints didn’t really lock when i set their limits to locked).
Now, in the release version, the “SetConstraintComponents->…” funcion of the PhysicsConstraintComponent doesn’t work anymore in my case, so the cylinders don’t connect and when i stop the game, i get the warning Constraint in '/Game/UEDPIE_0_level_1.level_1:PersistentLevel.BP_TreeDummyCylinder_C_18.PhysicsConstraintComponent_0' attempting to create a joint between objects that are both static. No joint created.
But when i check all kinds of functions of the cylinders to set and check the mobilty, they always say that the cylinders are movable and not static. I also tried putting the “SetConstraintComponents” function into the tick function in case the game doesn’t register them as movable in code in the constructor and beginPlay yet. But that didn’t work either.
Another problem that confuses me:
I spawn a cylinder as a blueprint that contains a cylinder mesh. I also made a c++ script “TreeDummyCylinder” as the Parent Class of the blueprint, and i spawn it as follows ATreeDummyCylinder* NewCylinder = GetWorld()->SpawnActor<ATreeDummyCylinder>(CylinderBlueprint, Position, Rotation, SpawnParams);
Somehow the function “SetSimulatePhysics” doesn’t work anymore (it worked in a preview version of UE5) and the only way i can enable/ disable physics is via the blueprint. The reason i’m telling you this is, or the reason because i turned off physics for the cylinders in the first place is, because when physics are enabled, the “SetActorScale3D” function does’t work. But when i disable SimulatePhysics in the blueprint, the “SetActorScale3D” function works.

So this is really messed up. So my questions are:
-why are the cylinder objects registered as “static”? (or is that just a but or something from the physics constraint?)
-why is SetSimulatePhysics not working?
-why is the SetActorScale3D not working when physics are enabled?

or alternative question:
-is there another way to procedurally generate a physical skeleton?

Did you ever find a solution to the issue with the constraints? I’m doing the same thing (trees made of cylinders and angular constraints) and having the same issue (UE5 complaining about them being static).

I abandoned the project, so it is quite a while ago when i worked on it, but i guess i fixed this issue.
Looking at my code now, instead of spawning a blueprint, i spawn a plain StaticMeshActor with

	AStaticMeshActor* NewMeshActor = GetWorld()->SpawnActor<AStaticMeshActor>(AStaticMeshActor::StaticClass(), Position, Rotation, SpawnParams);

and afterwards assign a mesh to it with

UStaticMeshComponent* MeshComponent = NewMeshActor->GetStaticMeshComponent();


where CylinderMesh is a UStaticMesh Pointer declared like
UPROPERTY(EditAnywhere, Category = "Tree Dummy") UStaticMesh* DummyCylinderMesh;
in my TreeGeneratorActor that is already placed in the world, so i can assign a mesh in the editor like in this screenshot
Screenshot 2022-06-15 121101

And then the PhyisicsConstraint is instanciated like this

UPhysicsConstraintComponent* NewPhysicsConstraint = NewObject<UPhysicsConstraintComponent>(NewMeshActor);

Hope this answer was understandable. If you have further questions or this didn’t work for you, i could look into my code and see if i made any other fix that i’m currenlty overseeing.

1 Like