# Sprite click events not firing

**URL:** <https://forums.unrealengine.com/t/sprite-click-events-not-firing/342925>\
**Category:** Asset Creation\
**Tags:** sprites, click-event, unreal-engine, question, CPP\
**Created:** [January 2, 2016, 7:47pm UTC](https://forums.unrealengine.com/t/sprite-click-events-not-firing/342925 "2016-01-02T19:47:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_b5cfa23f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b5cfa23f](https://forums.unrealengine.com/u/anonymous_user_b5cfa23f)\
**Post date:** [January 2, 2016, 7:47pm UTC](https://forums.unrealengine.com/t/sprite-click-events-not-firing/342925/1 "2016-01-02T19:47:07Z")

</div>

I’m creating a C++ tile class for tiles (sprites) on a 2D game board. The tiles will need to respond to mouse clicks (e.g. to allow moving the pieces).

The events seem to be registered properly because updating the collision properties (e.g. un-/checking `Simulation Generates Hit Events`, `Generate Overlap Events` or `Can Ever Affect Navigation`) from the editor while playing causes the clicks to work correctly. A freshly spawned tile (without in-editor edits) doesn’t respond to the same clicks, though.

Here’s my setup (from the constructor):

```
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("TileRoot"));

	TileSpriteComponent = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("TileSprite"));
	TileSpriteComponent->SetSprite(TileSprite);
	TileSpriteComponent->RegisterComponentWithWorld(GetWorld());
	TileSpriteComponent->AttachTo(RootComponent);
	TileSpriteComponent->MarkRenderStateDirty(); // To make the updated sprite render

```

In BeginPlay(…), I have this:

```
	OnClicked.AddUniqueDynamic(this, &ATerrainTile::OnClicked_Mouse);

```

Which simply logs a message (for now):

```
    // The tile was clicked by the mouse
    void ATerrainTile::OnClicked_Mouse()
    {
    	UE_LOG(LogTemp, Warning, TEXT("Tile %dx%d clicked"), TileRow, TileColumn);
    }

```

The tiles are using the `BlockAllDynamic` collision preset and therefore are set to Block for Visibility traces.

A few different searches have found suggestions like these:

- [Collision in code](https://forums.unrealengine.com/archive/index.php/t-73591.html)
- [C++ Collision detection?](https://answers.unrealengine.com/questions/141319/c-collision-detection.html)
- [Simulation Generate Hit Events boolean in C++?](https://answers.unrealengine.com/questions/127168/simulation-generate-hit-events-boolean-in-c.html)

These lead me to try all these in various combinations in the constructor and in BeginPlay(…), all without success:

```
	TileSpriteComponent->Mobility = EComponentMobility::Movable;
	TileSpriteComponent->bGenerateOverlapEvents = true;
	TileSpriteComponent->SetSimulatePhysics(true);
	TileSpriteComponent->SetEnableGravity(false);
	TileSpriteComponent->SetNotifyRigidBodyCollision(true);
	TileSpriteComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);

	SetActorEnableCollision(true);

```

I suspect I’m missing either a piece of the setup or some way to tell the engine to recheck the physics/collision, but I can’t seem to find it.

Can someone explain what I’m missing here?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b5cfa23f](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b5cfa23f](https://forums.unrealengine.com/u/anonymous_user_b5cfa23f)\
**Post date:** [January 13, 2016, 7:53pm UTC](https://forums.unrealengine.com/t/sprite-click-events-not-firing/342925/2 "2016-01-13T19:53:05Z")

</div>

I’ve finally found the cause of the issue. Registering the sprite components with the world somehow prevents the clicks from registering properly. In other words, all I had to do was remove this line:

```
TileSpriteComponent->RegisterComponentWithWorld(GetWorld());

```

I’m still not positive about why that line prevents the clicks I was using, but removing it solved my problem.
