Get point, where clicking on skeletal component

Tell me please, when i clicking on USkeletalMeshComponent of actor, how i can get coordinates of my point(x,y,z) and also how to get its component.

You can get the clicked point by doing a linetrace from the cursor’s screen position.
When the linetrace hits an actor, you can then get the point using HitResult.ImpactPoint.
HitResult.Actor will contain a pointer to the actor that was hit, which you can use to get its Skeletal Mesh Component.

// The clickable distance from the camera can be whatever distance you decide
float Distance = 10000;

FVector Start, End, WorldDirection;

// Get the start location and direction of the ray from the screen position
DeprojectScreenPositionToWorld(ScreenX, ScreenY, Start, WorldDirection);

End = Start + (WorldDirection * Distance);

FHitResult HitResult(ForceInit);

FCollisionQueryParams QueryParams = FCollisionQueryParams();
QueryParams.bTraceComplex = true;


if (HitResult.bBlockingHit)
	// The point on the actor that was clicked
	FVector ClickPoint = HitResult.ImpactPoint;

	// The actor that was hit by the linetrace
	TWeakObjectPtr<AActor> ClickActor = HitResult.Actor;

	// Get the skeletal mesh component from the actor if one exists
	TArray<USkeletalMeshComponent*> Components;

	if (Components.Num > 0)
		USkeletalMeshComponent* SkeletalMeshComponent = Components[0];

A simpler way to get the FHitResult from the cursor screen position would be to use the GetHitResultUnderCursor function.

APlayerController* PC = Cast<APlayerController>(GetController());

if (PC)
	FHitResult HitResult(ForceInit)	
	PC->GetHitResultUnderCursor(ECC_WorldDynamic, true, HitResult);

	// Get the click point, click actor, and skeletal mesh component as described before

add a if condition to check if the hit actor is your mesh.

I use the AddIgnoredActor function in the FCollisionQueryParams to ignore my player pawn, but I didn’t add that to the code because I don’t know the specifics of his game.
The game could have a feature where you place random objects on your character, haha.
He may not even have a player pawn.

Functions unfortunately does not work on the character. On StaticMesh fine. It may be necessary to apply any of the settings for the character or SkeletalMesh?


And if a character consists of several components, whether it is possible to determine which specific user clicked?

Linetraces will only detect collision components, so you would need to add at least one collision component to your character. The floor is being detected because is has a box collision component.
You can use HitResult.Component to get the specific component that was clicked.

Thanks very much - it works. Is it possible to create a UShapeComponent, which will be based on the geometry of the component?

You will probably want to create a physics asset for the character, which will consist of a number of primitive collision shapes attached to various bones of the character’s skeleton. It is more optimized this way compared to using mesh collision.
You can check out this tutorial series on how to set that up using the Physics Asset Tool: Introduction to the Physics Assets Tool (PhAT) | v4.2 | Unreal Engine - YouTube

Unfortunately, I can not understand how to use PhysAssets to determine click point. To test the created Skeletal mesh cylinder and PhysAsset.



And linetracer return zero-vector.

Sorry, it works great. Just needed to apply the settings UI in component attributes.


Thanks very much.