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"
9#include "Engine/World.h"
10
11#include "Kismet/GameplayStatics.h"
12#include "TimerManager.h"
13
14AInstancedActor::AInstancedActor(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
15{
16 StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent"));
17 RootComponent = StaticMeshComponent;
18 PrimaryActorTick.bCanEverTick = false;
19 InteractableName = NSLOCTEXT("Agrarsense", "StaticInstancedActorInteractableName", "Prop");
20}
21
23{
24 Super::BeginPlay();
25
27 {
28 // Check if Custom Depth has been setup in Editor, if not Tagger.cpp needs to do this runtime.
29 CustomDepthSetup = (StaticMeshComponent->bRenderCustomDepth && StaticMeshComponent->CustomDepthStencilValue == 0) ? true : false;
30 }
31
32 PreviousTransform = GetActorTransform();
33
35}
36
37void AInstancedActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
38{
39 Super::EndPlay(EndPlayReason);
40
41 if (EndPlayReason != EEndPlayReason::Type::EndPlayInEditor)
42 {
44 {
45 StaticMeshComponent->UnregisterComponent();
46 StaticMeshComponent->DestroyComponent();
47 StaticMeshComponent = nullptr;
48 }
49 }
50}
51
53{
55 {
56 return false;
57 }
58
60 if (InstancedRenderer)
61 {
62 return InstancedRenderer->AddActorToInstancedRendering(this);
63 }
64
65 return false;
66}
67
69{
71 {
72 StaticMeshComponent->SetVisibility(false);
73 StaticMeshComponent->SetComponentTickEnabled(false);
75 }
76}
77
79{
81 {
82 UStaticMesh* Mesh = StaticMeshComponent->GetStaticMesh();
83 if (Mesh)
84 {
85 FString Path = Mesh->GetPathName();
86 if (Path.Contains("Tree"))
87 {
88 return true;
89 }
90 }
91 }
92
93 return false;
94}
UStaticMeshComponent * StaticMeshComponent
FTransform PreviousTransform
AInstancedActor(const FObjectInitializer &ObjectInitializer)
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
bool AddedToInstancedRenderer
bool ShouldUpdateTransformAutomatically
virtual void BeginPlay() override
bool AddToInstancedRendering()
bool IsTreeActor() const
bool AddActorToInstancedRendering(AInstancedActor *InstancedActor)
static AInstancedRendererManager * GetInstancedRenderer(const UObject *WorldContextObject)