# How do you select a static mesh element by clicking the left mouse button in the running mode?

**URL:** <https://forums.unrealengine.com/t/how-do-you-select-a-static-mesh-element-by-clicking-the-left-mouse-button-in-the-running-mode/415222>\
**Category:** Asset Creation\
**Tags:** unreal-engine, hit, runtime, question\
**Created:** [January 22, 2018, 9:28am UTC](https://forums.unrealengine.com/t/how-do-you-select-a-static-mesh-element-by-clicking-the-left-mouse-button-in-the-running-mode/415222 "2018-01-22T09:28:08Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [January 24, 2018, 9:49am UTC](https://forums.unrealengine.com/t/how-do-you-select-a-static-mesh-element-by-clicking-the-left-mouse-button-in-the-running-mode/415222/23 "2018-01-24T09:49:34Z")

</div>

Sure thing, I can send you the project. But one last thing, could you double check the _material slot name_ and _material name_ in your mesh - they need to be the same for this to work properly:

![228225-untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/4/4/344e1ab73d48813a6994cffd031f1786e3a54070.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [January 24, 2018, 10:01am UTC](https://forums.unrealengine.com/t/how-do-you-select-a-static-mesh-element-by-clicking-the-left-mouse-button-in-the-running-mode/415222/24 "2018-01-24T10:01:52Z")

</div>

Sent you the project. Good luck!

---

<div class="post-metadata">

**Author:** ![Anonymous\_0cb7be7ba4bc64b9dcbb8d10d6e603f5](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_0cb7be7ba4bc64b9dcbb8d10d6e603f5](https://forums.unrealengine.com/u/Anonymous_0cb7be7ba4bc64b9dcbb8d10d6e603f5)\
**Post date:** [January 25, 2018, 3:36am UTC](https://forums.unrealengine.com/t/how-do-you-select-a-static-mesh-element-by-clicking-the-left-mouse-button-in-the-running-mode/415222/25 "2018-01-25T03:36:21Z")

</div>

Thank you very much. 么么哒！~

---

<div class="post-metadata">

**Author:** ![DesuIsSparta](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/desuissparta/32/88715_2.png) [@DesuIsSparta](https://forums.unrealengine.com/u/DesuIsSparta)\
**Post date:** [April 5, 2024, 6:42am UTC](https://forums.unrealengine.com/t/how-do-you-select-a-static-mesh-element-by-clicking-the-left-mouse-button-in-the-running-mode/415222/26 "2024-04-05T06:42:47Z")

</div>

This was never officially solved and I am experiencing the same issue in UE 5.3. The hit item is -1, element index is 0, and face index is -1. But it’s the correct mesh as when I print the object name it’s the right one. And I have the static mesh as the root of the blueprint, not that it should really matter.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/0/4/e04d8e44b889ffefb0e70b38d44b31aa005da77f.png)

Edit: I’ve figured it out. Well, kind of. It’s a limitation of using blueprints for raycasting. None of them allow the `bReturnFaceIndex` variable to be set to ‘true’ from the default/initial ‘false’ value, which in turn causes it to always be -1. If you walk through with a debugger, you can see the internal face index is correctly changing and the object you’re hitting has the proper material slots.

I guess the only solution for now is to write your own function via C++. Would be nice to have a parameter in a future official build though.

---

<div class="post-metadata">

**Author:** ![CodeArtworks\_Ltd](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/codeartworks_ltd/32/961810_2.png) [@CodeArtworks\_Ltd](https://forums.unrealengine.com/u/CodeArtworks_Ltd)\
**Post date:** [July 26, 2024, 1:16pm UTC](https://forums.unrealengine.com/t/how-do-you-select-a-static-mesh-element-by-clicking-the-left-mouse-button-in-the-running-mode/415222/28 "2024-07-26T13:16:54Z")

</div>

Here is a complete C++ solution.  
I basically modified the original function so that the caller has a control of setting the related params:

```auto
bool AMyGameGameMode::GetHitResultUnderCursorForObjects(APlayerController* controller,
	const TArray<TEnumAsByte<EObjectTypeQuery> >& ObjectTypes, bool traceComplex, bool returnFaceIndex, FHitResult& HitResult)const
{
	ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(controller->Player);
	bool bHit = false;
	if (LocalPlayer && LocalPlayer->ViewportClient)
	{
		FVector2D MousePosition;
		if (LocalPlayer->ViewportClient->GetMousePosition(MousePosition))
		{

			// Early out if we clicked on a HUD hitbox
			if (controller->GetHUD() != NULL && controller->GetHUD()->GetHitBoxAtCoordinates(MousePosition, true))
			{
				return false;
			}
			FVector WorldOrigin;
			FVector WorldDirection;
			if (UGameplayStatics::DeprojectScreenToWorld(controller, MousePosition, WorldOrigin, WorldDirection) == true)
			{

				FCollisionQueryParams collisionParams;
				collisionParams.TraceTag = SCENE_QUERY_STAT(ClickableTrace);
				collisionParams.bTraceComplex = traceComplex;
				collisionParams.bReturnFaceIndex = returnFaceIndex;

				FCollisionObjectQueryParams const ObjParam(ObjectTypes);
				return controller->GetWorld()->LineTraceSingleByObjectType(HitResult, 
					WorldOrigin, WorldOrigin + WorldDirection * controller->HitResultTraceDistance, ObjParam, collisionParams);
			}

			return false;
		}
	}

	if (!bHit)	//If there was no hit we reset the results. This is redundant but helps Blueprint users
	{
		HitResult = FHitResult();
	}

	return bHit;
}

```

[Previous page](https://forums.unrealengine.com/t/how-do-you-select-a-static-mesh-element-by-clicking-the-left-mouse-button-in-the-running-mode/415222.md?page=1)
