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.
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 = GetOwner(); if (Parent) { Parent->SetActorLocation( Parent->GetActorLocation() + FVector( FMath::FRandRange(-1, 1)* MovementRadius, FMath::FRandRange(-1, 1)* MovementRadius, FMath::FRandRange(-1, 1)* MovementRadius)); }
Verify...