Download

Constraints spawned in debug-runtime is broken

Compiled in **GameDebug Editor

**

&stc=1

Compiled in **Development Editor **all work fine

&stc=1



ADefaultRadar::ADefaultRadar(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
    PrimaryActorTick.bCanEverTick = true;


    radar_part1 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("part1"));
    ConstructorHelpers::FObjectFinder<UStaticMesh> mesh_finder1(TEXT("StaticMesh'/Game/Tanks/DefaultTank/DefaulRadar_Part1.DefaulRadar_Part1'"));
    UStaticMesh* part1_mesh = nullptr;


    if (mesh_finder1.Succeeded())
        part1_mesh = mesh_finder1.Object;
    else
        part1_mesh = LoadObject<UStaticMesh>(NULL, TEXT("StaticMesh'/Game/Tanks/DefaultTank/DefaulRadar_Part1.DefaulRadar_Part1'"), NULL, LOAD_None, NULL);


    radar_part1->SetStaticMesh(part1_mesh);
    radar_part1->SetSimulatePhysics(true);
    radar_part1->SetAngularDamping(2.0);
    radar_part1->SetMassOverrideInKg(NAME_None, 0.1f);
    radar_part1->BodyInstance.bStartAwake = false;
    RootComponent = radar_part1;




    radar_part2 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("part2"));
    ConstructorHelpers::FObjectFinder<UStaticMesh> mesh_finder2(TEXT("StaticMesh'/Game/Tanks/DefaultTank/DefaulRadar_Part2.DefaulRadar_Part2'"));
    UStaticMesh* part2_mesh = nullptr;


    if (mesh_finder2.Succeeded())
        part2_mesh = mesh_finder2.Object;
    else
        part2_mesh = LoadObject<UStaticMesh>(NULL, TEXT("StaticMesh'/Game/Tanks/DefaultTank/DefaulRadar_Part2.DefaulRadar_Part2'"), NULL, LOAD_None, NULL);


    radar_part2->SetStaticMesh(part2_mesh);
    radar_part2->SetSimulatePhysics(true);
    radar_part2->SetAngularDamping(2.0);
    radar_part2->BodyInstance.bStartAwake = false;
    radar_part2->SetMassOverrideInKg(NAME_None, 0.1);
    radar_part2->AttachToComponent(radar_part1, FAttachmentTransformRules::KeepRelativeTransform, FName("Radar"));




    FVector sp = radar_part1->GetSocketLocation(FName("Radar"));
    FConstraintInstance ci;
    ci.bDisableCollision = true;
    ci.LinearXMotion = ELinearConstraintMotion::LCM_Locked;
    ci.LinearYMotion = ELinearConstraintMotion::LCM_Locked;
    ci.LinearZMotion = ELinearConstraintMotion::LCM_Locked;
    ci.AngularSwing1Motion = EAngularConstraintMotion::ACM_Free;
    ci.AngularSwing2Motion = EAngularConstraintMotion::ACM_Locked;//ACM_Locked
    ci.AngularTwistMotion = EAngularConstraintMotion::ACM_Locked;//ACM_Locked
    ci.bAngularBreakable = false;
    ci.bLinearBreakable = false;
    ci.SetAngularDriveParams(10000, 10000, 0);
    ci.AngularDriveMode = EAngularDriveMode::TwistAndSwing;
    ci.SetAngularVelocityTarget(FVector(0, 0, 0.5));
    ci.SetAngularVelocityDrive(true, false);


    radar_joint = NewObject<UPhysicsConstraintComponent>(radar_part1, TEXT("radar_joint"));
    radar_joint->ConstraintInstance = ci;
    radar_joint->AttachToComponent(radar_part1, FAttachmentTransformRules::KeepRelativeTransform, FName("Radar"));
    radar_joint->SetRelativeRotation(FRotator(0, 0, 0));
    radar_joint->SetConstrainedComponents(radar_part1, NAME_None, radar_part2, NAME_None);
}


void ADefaultRadar::BeginPlay()
{
    Super::BeginPlay();
    radar_joint->SetAngularVelocityDrive(true, false);
    radar_joint->SetAngularVelocityTarget(FVector(0, 0, 0.5));
}


void ADefaultRadar::Tick( float DeltaTime )
{
    Super::Tick( DeltaTime );


}


ADefaultTank::BeginPlay()



    FVector rs = dt->tower_comp->GetSocketLocation(FName("Tank01_Tower_02"));
    radar = GetWorld()->SpawnActor<ADefaultRadar>(rs, this->GetActorRotation());
    ADefaultRadar* rd = Cast<ADefaultRadar>(radar);
    
    FConstraintInstance rci;
    rci.bDisableCollision = true;
    rci.LinearXMotion = ELinearConstraintMotion::LCM_Locked;
    rci.LinearYMotion = ELinearConstraintMotion::LCM_Locked;
    rci.LinearZMotion = ELinearConstraintMotion::LCM_Locked;
    rci.AngularSwing1Motion = EAngularConstraintMotion::ACM_Locked;
    rci.AngularSwing2Motion = EAngularConstraintMotion::ACM_Locked;//ACM_Locked
    rci.AngularTwistMotion = EAngularConstraintMotion::ACM_Locked;//ACM_Locked
    rci.bAngularBreakable = false;
    rci.bLinearBreakable = false;
    
    radar_joint = NewObject<UPhysicsConstraintComponent>(dt->tower_comp, TEXT("radar_joint"));
    radar_joint->ConstraintInstance = rci;
    radar_joint->AttachToComponent(dt->tower_comp, FAttachmentTransformRules::KeepRelativeTransform, FName("Tank01_Tower_02"));
    radar_joint->SetConstrainedComponents(dt->tower_comp, NAME_None, rd->radar_part1, NAME_None);