Download

[Bug] Enable physics working on one blueprint but not the other

I can’t upload picture in the answerhub for no reason so I have to post it here.

I have two blueprints here:

As you can see, the only difference is, that one is inhereted from AActor and the other from AGun (which itself is an Actor).
I expect, that both blueprints behavive the same in terms of physics when I start the game, but they don’t.

The blueprint, that inherts from AGun just stays in the air without moving, although physics are enabled for the root component.
Here is the code from the constructor:


 AGun::AGun()
{
Mesh3P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh3P"));
RootComponent = Mesh3P;
Mesh3P->bReceivesDecals = false;
Mesh3P->CastShadow = true;
Mesh3P->bOwnerNoSee = true;
Mesh3P->SetCollisionObjectType(ECC_PhysicsBody);
Mesh3P->SetCollisionEnabled(ECollisionEnabled::NoCollision);
Mesh3P->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Mesh1P"));
Mesh1P->MeshComponentUpdateFlag = EMeshComponentUpdateFlag::OnlyTickPoseWhenRendered;
Mesh1P->bReceivesDecals = false;
Mesh1P->CastShadow = false;
Mesh1P->bOnlyOwnerSee = true;
Mesh1P->SetCollisionObjectType(ECC_WorldDynamic);
Mesh1P->SetCollisionEnabled(ECollisionEnabled::NoCollision);
Mesh1P->SetupAttachment(RootComponent);
currentState = EWeaponState::Idle;
MuzzleAttachPoint = "Muzzle";
cooldown = 0.15f;
lineTraceRange = 10000.0f;
}
 

Note that I have of course enabled physics and collision on the object that I placed in the world, as you can see from the screenshots.
When I detach the gun from the carrier, the function UnEquipWeapon() is called, which should enable physics:


 voidAGun::UnEquipWeapon()
{
bCanShoot = false;
DetachMeshFromPawn();
this->DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
MyPawn = nullptr;
if (Mesh3P)
{
Mesh3P->SetHiddenInGame(false);
Mesh3P->SetSimulatePhysics(true);
Mesh3P->SetCollisionProfileName("Ragdoll");
Mesh3P->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
Mesh3P->bOwnerNoSee = false;
}
if (Mesh1P)
{
Mesh1P->SetHiddenInGame(true);
Mesh1P->AttachToComponent(Mesh3P, AttachmentTransformRules::SnapToTargetNotIncludingScale);
}
}
voidAGun::DetachMeshFromPawn()
{
if (Mesh3P)
{
Mesh3P->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
Mesh3P->SetHiddenInGame(true);
}
if (Mesh1P)
{
Mesh1P->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
Mesh1P->SetHiddenInGame(true);
}
}
 

It does enable physics and collision, but the gun does not simulate phyics at all. It just stays in the air. I don’t get any warning or errors in the console.
Both blueprints use the same mesh.
What the **** is this ****?