Download

Attaching with welding - how to keep collision?

I’m trying to attach a heirachy of StaticMeshComponents to my pawn, and having all sorts of trouble. The pawn is simulating physics, and that works fine.

When I attach my new component however, odd things happen. I receive hit notifications - and I can see the collision between the new welded object and other objects, but the new welded objects pass through things, even though they generate a hit. The original pawn mesh continues to block objects and generate hits.

So I have a MiningComponent, which attaches a StaticMeshComponent to itself (MiningActiveMesh), and then I attach the MiningComponent to my pawn:

Here’s the setup for the MiningComponent:



UMiningComponent::UMiningComponent(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	
	SetCollisionProfileName(TEXT("BlockAll"));
	SetSimulatePhysics(true); 
	SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	SetNotifyRigidBodyCollision(true);

	MiningActiveMesh = NULL;
	bGenerateOverlapEvents = true;
	
}





// Called when the game starts
void UMiningComponent::InitializeComponent()
{
	Super::InitializeComponent();
	
	if (MiningActiveMesh == NULL)
	{
		GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString("Creating equipment component failed - null object!"));
		return;
	}
	//equip_top = EquipmentToAttach.GetDefaultObject<UEquipmentComponent>();
	MiningActiveComponent = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass(), this);
	if (!MiningActiveComponent)
	{
		GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString("Creating MiningActiveComponent failed!"));
		return;
	}

	MiningActiveComponent->SetSimulatePhysics(true);
	MiningActiveComponent->SetNotifyRigidBodyCollision(true);
	
	MiningActiveComponent->SetStaticMesh(MiningActiveMesh);
	MiningActiveComponent->AttachTo(this, MiningActiveSocket,EAttachLocation::KeepRelativeOffset,true);
	MiningActiveComponent->SetVisibility(false, true);

	MiningActiveComponent->SetCollisionProfileName(TEXT("BlockAll"));
	MiningActiveComponent->RegisterComponentWithWorld(GetWorld());
}


And here’s how I spawn and attach the MiningComponent to my pawn:



       
        UEquipmentComponent* NewEquipment = ConstructObject<UEquipmentComponent>(EquipmentToAttach,this);
	if (!NewEquipment)
	{
		GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString("Creating equipment component failed!"));
		return;
	}

	FName SocketName = FName(*SocketNames(int)AttachmentPoint]);
	NewEquipment->AttachTo(StaticMeshComponent, SocketName,EAttachLocation::KeepRelativeOffset,true);
	NewEquipment->SetVisibility(true,true);
	NewEquipment->PlayerPawn = this;
	NewEquipment->RegisterComponentWithWorld(GetWorld());
	NewEquipment->ReceiverID = UniqueID;
	NewEquipment->PostAttach();



Does anyone have any suggestions?

Ok, I gave up on welding, I tried everything I could think of and I couldn’t get it to work. Instead I added a physics constraint with no attachment and now everything works fine.