Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*--- PositionReport.h ---*/
- #pragma once
- #include "CoreMinimal.h"
- #include "Gameframework/Actor.h"
- #include "Components/ActorComponent.h"
- #include "PositionReport.generated.h"
- UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
- class BUILDINGESCAPE_API UPositionReport : public UActorComponent
- {
- GENERATED_BODY()
- public:
- // Sets default values for this component's properties
- UPositionReport();
- protected:
- // Called when the game starts
- virtual void BeginPlay() override;
- public:
- // Called every frame
- virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
- };
- /*--- /PositionReport.h ---*/
- /*--- PositionReport.cpp ---*/
- #include "PositionReport.h"
- // Sets default values for this component's properties
- UPositionReport::UPositionReport()
- {
- // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
- // off to improve performance if you don't need them.
- PrimaryComponentTick.bCanEverTick = true;
- // ...
- }
- // Called when the game starts
- void UPositionReport::BeginPlay()
- {
- Super::BeginPlay(); // `BeginPlay()`: Cannot initialize object parameter of type 'UActorComponent' with an expression of type 'UPositionReport'
- FString ObjectName = GetOwner()->GetName(); // `GetOwner()` Cannot initialize object parameter of type 'const UActorComponent' with an expression of type 'UPositionReport'
- FString ObjectLocationStr = GetOwner()->GetActorLocation().ToString();
- UE_LOG(LogTemp, Warning, TEXT("%s is reporting duty on %s!"), *ObjectName, *ObjectLocationStr);
- }
- // Called every frame
- void UPositionReport::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
- {
- Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
- // ...
- }
- /*--- /PositionReport.cpp ---*/
Add Comment
Please, Sign In to add comment