Agrarsense
InstancedActor.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#include "InstancedActor.h"
7#include "Engine/World.h"
8
9#include "Kismet/GameplayStatics.h"
10#include "TimerManager.h"
11
12AInstancedActor::AInstancedActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
13{
14 StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent"));
15 RootComponent = StaticMeshComponent;
16 PrimaryActorTick.bCanEverTick = false;
17 InteractableName = NSLOCTEXT("Agrarsense", "StaticInstancedActorInteractableName", "Prop");
18}
19
21{
22 Super::BeginPlay();
23
25 {
26 // Check if Custom Depth has been setup in Editor, if not Tagger.cpp needs to do this runtime.
27 CustomDepthSetup = (StaticMeshComponent->bRenderCustomDepth && StaticMeshComponent->CustomDepthStencilValue == 0) ? true : false;
28 }
29
30 PreviousTransform = GetActorTransform();
31}
32
33void AInstancedActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
34{
35 Super::EndPlay(EndPlayReason);
36
37 if (EndPlayReason != EEndPlayReason::Type::EndPlayInEditor)
38 {
40 {
41 StaticMeshComponent->UnregisterComponent();
42 StaticMeshComponent->DestroyComponent();
43 StaticMeshComponent = nullptr;
44 }
45 }
46}
47
49{
51 {
52 return false;
53 }
54 return true;
55}
56
58{
60 {
61 StaticMeshComponent->SetVisibility(false);
62 StaticMeshComponent->SetComponentTickEnabled(false);
64 }
65}
66
68{
70 {
71 UStaticMesh* Mesh = StaticMeshComponent->GetStaticMesh();
72 if (Mesh)
73 {
74 FString Path = Mesh->GetPathName();
75 if (Path.Contains("Tree"))
76 {
77 return true;
78 }
79 }
80 }
81
82 return false;
83}
UStaticMeshComponent * StaticMeshComponent
FTransform PreviousTransform
bool CanAddToInstancedRenderer()
AInstancedActor(const FObjectInitializer &ObjectInitializer)
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
bool AddedToInstancedRenderer
bool ShouldUpdateTransformAutomatically
virtual void BeginPlay() override
bool IsTreeActor() const