[4.2] Simulate Physics issues

Kris
Fri, 13 Jun 2014 03:56:56 +0000
World Creation

G’day,

Since switching from 4.1 to 4.2, we’ve been having issue with attaching items.

If the item is spawned and immediately attached to the player or another item, everything works as expected.

If the item is pre-placed, it will not attach when told too.
Also, depending on the map, the item will fall through the world when you try to attach it.

All items have their collision disabled on spawn:

					// Static mesh based inventory items often have collision enabled by default.
					// Just in case this is the case now, set every component to no collision.
					PrimitiveComp->SetSimulatePhysics(false);
					PrimitiveComp->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);

Pre-placed items have their collision and physics enabled shortly after spawn.
Both use the same function to attach.

The collision profile it uses while in-game or attached is a custom profile called “ItemPickup”:

+Profiles=(Name="ItemPickup",CollisionEnabled=QueryAndPhysics,ObjectTypeName="ItemPickup",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel=ProjectilePenetration, Response=ECR_Overlap),(Channel=ItemOverlap, Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="",bCanModify=False)

Pre-placed and dropped items have their physics enabled with the following piece of code:

		USkeletalMeshComponent* SkelMeshComponent = Cast<USkeletalMeshComponent>(PrimitiveComp);

		if (SkelMeshComponent && SkelMeshComponent->SkeletalMesh)
		{
			SkelMeshComponent->bBlendPhysics = false;
			SkelMeshComponent->SetAllBodiesSimulatePhysics(false);
			SkelMeshComponent->bEnablePhysicsOnDedicatedServer = true;
		}

		PrimitiveComp->SetSimulatePhysics(true);

		static FName CollisionProfileName(TEXT("ItemPickup"));
		PrimitiveComp->SetCollisionProfileName(CollisionProfileName);
		SetActorEnableCollision(true);

All items are attached with the following:

		if (UPrimitiveComponent* PrimitiveComp = GetRootPrimitiveComponent())
		{
			// Disable physics simulation.
			PrimitiveComp->SetSimulatePhysics(false);

			// Enable collision raycasts, sweeps and overlaps.
			PrimitiveComp->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
			PrimitiveComp->SetCollisionObjectType(COLLISION_ITEM_PICKUP);
			PrimitiveComp->SetCollisionResponseToAllChannels(ECR_Ignore);

			// Must be enabled, otherwise raycasts, sweeps and overlaps will fail.
			SetActorEnableCollision(true);
		}

		// Give the Blueprint a chance to attach us, but if that fails, do it here.
		if (!BlueprintAttachTo(AttachmentInfo))
		{
			RootComponent->SetRelativeLocationAndRotation(AttachmentInfo.LocationOffset, AttachmentInfo.RotationOffset);
			RootComponent->AttachTo(AttachmentInfo.AttachComponent, AttachmentInfo.AttachSocket, EAttachLocation::KeepRelativeOffset);
		}

Despite calling PrimitiveComp->SetSimulatePhysics(false), simulate physics remains true, which causes AttachTo() to fail.

SetCollisionXXX seemed to be the cause, though strangely, even if I set it use to the no collision profile, it still causes the same problem.

In an attempt to fix the issue, I rearranged the code a bit. Oddly, this worked for some maps, but not for others. Why would it work for some maps, but not others?

Given this odd behaviour, I figure this has to be a bug.

May be the same issue described in the post Collision settings chaning when being attached to other objects.

Very frustrating
Thoughts or suggestions welcome.

Kris

2 posts - 1 participant