Physical Constraint Angular Velocity Issue: Rotation Stops and Won't Restart

Hello,

I just started learning Unreal Engine and I have a strange behaviour.
I’m working with a physical constraint component linking two cubes. The constraint is configured with angular velocity, but I’m encountering inconsistent behavior:

  1. Initialization:
  • If I set a non-zero target velocity (e.g., (0.0, 0.0, 0.1)) in the editor, the rotation starts as expected, but after stopping it via code, the rotation won’t restart.
  • If initialized with (0.0, 0.0, 0.0), it doesn’t spin at all when I try to apply a velocity target programmatically.
  1. Code Behavior:
  • Using SetAngularVelocityTarget toggles the velocity between (0.0, 0.0, 0.1) (to spin) and (0.0, 0.0, 0.0) (to stop).
  • The constraint spins correctly the first time but fails to restart after stopping.

Here is my setting in the editor

And this is my Code Snipped:

RotationComponentForActor.h

#pragma once

include “CoreMinimal.h”
include “Components/ActorComponent.h”
include “PhysicsEngine/PhysicsConstraintComponent.h”

include “RotationComponentForActor.generated.h”

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class CRYPTRAIDER_API URotationComponentForActor : public UActorComponent
{
GENERATED_BODY()

public:
// Sets default values for this component’s properties
URotationComponentForActor();
int counter = 0;
int counter2 = 0;
protected:
// Called when the game starts
virtual void BeginPlay() override;

public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

};

RotationComponentForActor.cpp

// Fill out your copyright notice in the Description page of Project Settings.

include “UObject/NameTypes.h”
include “Components/SkeletalMeshComponent.h”

include “RotationComponentForActor.h”

// Sets default values for this component’s properties
URotationComponentForActor::URotationComponentForActor()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don’t need them.
PrimaryComponentTick.bCanEverTick = true;

// ...

}

// Called when the game starts
void URotationComponentForActor::BeginPlay()
{
Super::BeginPlay();
}

// Called every frame
void URotationComponentForActor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
counter++;

if((1/DeltaTime*2) < counter )
{
	TSet<UActorComponent*> Components = GetOwner()->GetComponents();
	for (UActorComponent* Component : Components)
	{
		//UE_LOG(LogTemp, Warning, TEXT("Component: %s!"), *Component->GetName());
		if (UPhysicsConstraintComponent *buffer = Cast<UPhysicsConstraintComponent>(Component)) //if (USkeletalMeshComponent  * Constraint = Cast<USkeletalMeshComponent>(Component))
		{

			if(counter2%2)
			{
				UE_LOG(LogTemp, Display, TEXT("mod2"));
				buffer->SetAngularDriveMode(EAngularDriveMode::TwistAndSwing);
				buffer->SetAngularOrientationDrive(true,false);
				buffer->SetAngularDriveParams(10.0f, 180.0f, 0.0f); // Strength, damping, force limit
				buffer->SetAngularVelocityTarget(FVector(0.0, 0.0, 0.8));
				counter2++;
			}
			else
			{
				UE_LOG(LogTemp, Display, TEXT("mod1"));
				buffer->SetAngularVelocityTarget(FVector(0.0, 0.0, 0.0));
				counter2++;

			}
			counter=0;
		}

	}
}
// ...

}

I believe your simulated object is ‘sleeping’. The physics system only runs its simulation for objects which are ‘awake’, as a performance optimization. If you search in the API documentation for the keywords sleep & wake on this page:

:you will find many methods for managing and checking if your object is awake or sleeping.

I think you can call this method for your controlled object (not the controlling object) when you want the simulation to start again (when you apply the angular velocity target):

I am not an expert in this area (or any other) but I think rigid bodies are normally woken up automatically when they are impacted by another rigid body or a character. While they are moving they will be awake and their position will be calculated every physics tick and then when their movement reaches below a certain threshold they are put to sleep and the physics system can ignore them to improve performance.

Thanks! I’ll give it a shot