Creating a custom Actor Component

Actor components are an easy way to implement common functionality that should be shared between Actors. Actor components aren't rendered, but can still perform actions such as subscribing to events, or communicating with other components of the Actor that they are present within.

How to do it...

  1. Create an ActorComponent named RandomMovementComponent using the Editor wizard. Add the following class specifiers to the UCLASS macro:
    UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
  2. Add the following UPROPERTY to the class header:
    UPROPERTY()
    float MovementRadius;
  3. Add the following to the constructor's implementation:
    MovementRadius = 0;
  4. Lastly, add this to the implementation of TickComponent( ):
    AActor* Parent ...

Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.