# Counter's events

Published 2024-05-13

The ECEntityCounter class has 4 events replicated to all clients (server authoritative). These four events are public and can be used from C++ code or from Blueprint.

# Events

  • OnEntityAdded (AActor* NewEntity, int32 NewCount): Fired every time an entity is added to the count.
  • OnEntityRemoved (AActor* RemovedEntity, int32 NewCount): Fired every time an entity is removed from the count.
  • OnCountReachStep (int32 Step): Fired when the counter reaches a step and gives the step value as parameter.
  • OnCoutReachGoal (): Fired when the counter reaches the goal.

# Bindings

To easily bind your events in your blueprint actor you can use the blueprint implementable version of the event. To do so, on the right side of the FUNCTIONS section, click on override and select the event you want to implement.

Once clicked it will generate the blueprint nodes allowing you to implement this event in your actor.

In C++ code, just get your EntityCounter actor and bind a callback to the public delegate associated with the event you need.

AECEntityCounter* EntityCounter = ... // Get a reference to the counter you want yor code to bind to
EntityCounter->OnEntityAdded.AddDynamic(this, &APSPlayerCharacter::OnEntityDetected);
EntityCounter->StartDetection();