Download

AttachRootComponentTo: Why Doesn't it Work?

Calling


Item->SkeletalMeshComponent->SetSimulatePhysics(false);
Item->AttachRootComponentTo(this, AttachmentSocketName, EAttachLocation::SnapToTarget);

Doesn’t move the item, turn off its physics, or attach it to the socket. The socket name is valid, as their are other functions that use it. Any guesses as to what I am doing wrong?

The Item’s .cpp


AVRInventoryItem::AVRInventoryItem(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	SkeletalMeshComponent->SetSimulatePhysics(true);
}

The .h


UCLASS()
class AVRInventoryItem : public ASkeletalMeshActor
{
};


Hi,

Check the output log, there are a number of different things that can cause attachment to fail in USceneComponent::AttachTo but they should all log a message.

Cheers,
Michael Noland

When I play in editor, there is nothing related to component attaching in the output log.

Also, but only somewhat related, the item simulates physics correctly and collides about 60% of the time. The other 40% it falls through the floor.

If the info helps, these 2 lines work as expected


Item->SetActorLocation(IRot);
Item->SetActorRotation(IRot);

These appear to have no effect whatsoever.


Item->SkeletalMeshComponent->SetAllPhysicsPosition(ILoc);
Item->SkeletalMeshComponent->SetAllPhysicsRotation(IRot);
Item->SkeletalMeshComponent->SetAllPhysicsLinearVelocity(LinVel, false);
Item->SkeletalMeshComponent->SetAllPhysicsAngularVelocity(AngularVel, false);

Not sure then. Are you building the engine or using the launcher version? If you’re building the engine, I’d step into the function and see what’s going on.

For the collision issue, check out the collision of the object and the floor with show collision or pxviz, see if anything seems wrong/unexpected, or if the floor collision is really thin or something.

Cheers,
Michael Noland

Building the engine. Collision on the floor looks ok, its the shooter template level. How many units is too thin for proper collision?

EDIT:
OnPickup
Item->SkeletalMeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);

On drop
Item->SkeletalMeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);

These seem to get it to attach properly. I also set CCD on in its blueprint and it seems to stop falling through the floor for now… I’m not sure what I’m doing wrong with trying to give it velocity and angular velocity though…