# StaticMesh onclicked

**URL:** <https://forums.unrealengine.com/t/staticmesh-onclicked/306234>\
**Category:** C++\
**Tags:** onclick, actor, unreal-engine, staticmesh, CPP, question\
**Created:** [February 7, 2015, 2:33am UTC](https://forums.unrealengine.com/t/staticmesh-onclicked/306234 "2015-02-07T02:33:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JitinDhillon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JitinDhillon](https://forums.unrealengine.com/u/JitinDhillon)\
**Post date:** [February 7, 2015, 2:33am UTC](https://forums.unrealengine.com/t/staticmesh-onclicked/306234/1 "2015-02-07T02:33:26Z")

</div>

I’m having trouble figuring out how to handle click events for an Actor mesh in c++ code.

Everything is set up in the editor, I can add a onclick event to the mesh in the blueprint and it works fine with my planned logic, but I want to have this in the code.

I looked around and found this: [OnClicked Parameters - Programming & Scripting - Unreal Engine Forums](https://answers.unrealengine.com/questions/142387/onclicked-parameters.html)  
However I am not having any luck with my method being triggered.

cpp file

```
 AShipActor::AShipActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer){
ShipMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("ShipMesh"));
	ShipMesh->AttachTo(RootComponent);
	ShipMesh->OnClicked.AddDynamic(this, &AShipActor::OnClicked);
};

void AShipActor::OnClicked(UPrimitiveComponent* pComponent){
	//my logic
}

```

Any help would be greatly appreciated!  
Thanks

---

<div class="post-metadata">

**Author:** ![FortuneStudios](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FortuneStudios](https://forums.unrealengine.com/u/FortuneStudios)\
**Post date:** [February 7, 2015, 12:18pm UTC](https://forums.unrealengine.com/t/staticmesh-onclicked/306234/2 "2015-02-07T12:18:39Z")

</div>

Hey, have you enabled click events in the controller?

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [February 7, 2015, 12:53pm UTC](https://forums.unrealengine.com/t/staticmesh-onclicked/306234/3 "2015-02-07T12:53:32Z")

</div>

I’m not sure but i think you can’t set collision based events on mesh which may be quite complex shape, it would be preference issue, try using some shape component on top of a mesh as click hitbox

---

<div class="post-metadata">

**Author:** ![JitinDhillon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JitinDhillon](https://forums.unrealengine.com/u/JitinDhillon)\
**Post date:** [February 8, 2015, 2:29am UTC](https://forums.unrealengine.com/t/staticmesh-onclicked/306234/4 "2015-02-08T02:29:51Z")

</div>

I changed my implementation to follow the TowerDefence example project, in which click events are handled in the PlayerController, and the click determines if an actor is underneath the cursor, which you can call methods on and perform onclick logic.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_cfbde766](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_cfbde766](https://forums.unrealengine.com/u/anonymous_user_cfbde766)\
**Post date:** [April 20, 2015, 1:29pm UTC](https://forums.unrealengine.com/t/staticmesh-onclicked/306234/5 "2015-04-20T13:29:43Z")

</div>

Can you please provide me the link for TowerDefence example project? I have same problem, could you more explanation is possible.
