How to do it...

  1. Create an ActorComponent named RandomMovementComponent using the Editor wizard:
  1. Add the following UPROPERTY to the class header in the public section:
#pragma once#include "CoreMinimal.h"#include "Components/ActorComponent.h"#include "RandomMovementComponent.generated.h"UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )class CHAPTER_04_API URandomMovementComponent : public UActorComponent{    GENERATED_BODY()public:     // Sets default values for this component's properties    URandomMovementComponent();    UPROPERTY()    float MovementRadius;protected:    // Called when the game starts    virtual void BeginPlay() override;

Get Unreal Engine 4.x Scripting with C++ Cookbook - Second Edition 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.