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...
- Create an
ActorComponent
namedRandomMovementComponent
using the Editor wizard. Add the following class specifiers to theUCLASS
macro:UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
- Add the following
UPROPERTY
to the class header:UPROPERTY() float MovementRadius;
- Add the following to the constructor's implementation:
MovementRadius = 0;
- 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.