O'Reilly logo

Unreal Engine 4 Scripting with C++ Cookbook by Stephen Whittle, William Sherif

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required