Agrarsense
Public Member Functions | Public Attributes | Private Attributes | List of all members
AInstancedActor Class Reference

#include <InstancedActor.h>

Inheritance diagram for AInstancedActor:
Inheritance graph
[legend]
Collaboration diagram for AInstancedActor:
Collaboration graph
[legend]

Public Member Functions

 AInstancedActor (const FObjectInitializer &ObjectInitializer)
 
virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
bool AddToInstancedRendering ()
 
void RemoveFromInstancedRendering (bool EnableStaticMeshComponent=true)
 
void UpdateTransformPosition ()
 
void InstanceAdded (int32 CompIndex, int32 InstanceNum)
 
void UpdateIndex (int32 UpdatedIndex)
 
void SetTypeAndModel (const FString &Type, const FString &Model)
 
bool IsTreeActor () const
 
void UpdatePreviousTransform (const FTransform &NewTransform)
 
bool IsAddedToInstancedRendering () const
 
UStaticMeshComponent * GetStaticMeshComponent () const
 
int GetInstanceStartCullDistance () const
 
int GetInstanceEndCullDistance () const
 
bool UpdateTransformAutomatically () const
 
FString GetTypeIDString () const
 
FString GetModelIDString () const
 
int GetComponentIndex () const
 
int GetInstanceIndex () const
 
bool HasAlternativeMaterial () const
 
bool IsCustomDepthSetup () const
 
bool GetAllowWorldPositionOffsetDisable () const
 
FTransform GetPreviousTransform () const
 
virtual FText GetInteractableName_Implementation () const override
 
virtual FTransform GetInteractableWorldTransform_Implementation () const override
 
virtual FString GetActorID_Implementation () const override
 
virtual FString GetActorName_Implementation () const override
 
virtual void SetActorName_Implementation (const FString &NewActorName) override
 
virtual void SetActorIDAndName_Implementation (const FString &NewActorName, const FString &NewID) override
 
- Public Member Functions inherited from IInteractable
FText GetInteractableName () const
 
FTransform GetInteractableWorldTransform () const
 
- Public Member Functions inherited from IActorInformation
FString GetActorID () const
 
FString GetActorName () const
 
FString GetActorInformation () const
 
void SetActorName (const FString &NewActorName)
 
void SetActorIDAndName (const FString &NewActorName, const FString &NewID)
 

Public Attributes

UStaticMeshComponent * StaticMeshComponent = nullptr
 
bool AllowWorldPositionOffsetDisable = false
 
bool AddToInstancedRenderer = true
 
int InstanceStartCullDistanceInCm = 45000
 
int InstanceEndCullDistanceInCm = 46500
 
bool ShouldUpdateTransformAutomatically = false
 
bool AlternativeMaterial = false
 
FText InteractableName
 

Private Attributes

FString ActorName
 
FString ActorID
 
FTransform PreviousTransform
 
int32 ComponentIndex = 9999999
 
int32 InstanceNumber = 9999999
 
bool AddedToInstancedRenderer = false
 
FString TypeID = "none"
 
FString ModelID = "none"
 
bool CustomDepthSetup = false
 

Additional Inherited Members

- Static Public Member Functions inherited from IActorInformation
static void SetAndValidateActorIDAndName (FString &ActorName, FString &ActorID, TWeakObjectPtr< AActor > Actor)
 
static bool DestroyActorByID (const FString &ID)
 
static AActor * GetActorByID (const FString &ID)
 
template<typename T >
static TArray< T * > GetActorsWithInterface ()
 
static void PrintAllIds ()
 

Detailed Description

Instanced Actor class. InstancedRenderer.cpp renders all of these Actors efficiently with UInstancedStaticMeshComponent. see InstancedRenderer.cpp

To use this:

  1. Create blueprint based of this Actor class in Unreal Editor
  2. Setup StaticMeshComponent to desired mesh in the blueprint.
  3. Place the Actors to the World in any way.

Note. If you need to move the Actor, you either call UpdateTransformPosition() each time you change the position, or Set UpdateTransformAutomatically to true in Blueprint or call SetUpdateTransformAutomatically(true); It's recommeded to keep UpdateTransformAutomatically false or call SetUpdateTransformAutomatically(false); If you don't need any Transform updates since this adds some performance cost.

Definition at line 37 of file InstancedActor.h.

Constructor & Destructor Documentation

◆ AInstancedActor()

AInstancedActor::AInstancedActor ( const FObjectInitializer &  ObjectInitializer)

Definition at line 14 of file InstancedActor.cpp.

14 : Super(ObjectInitializer)
15{
16 StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMeshComponent"));
17 RootComponent = StaticMeshComponent;
18 PrimaryActorTick.bCanEverTick = false;
19 InteractableName = NSLOCTEXT("Agrarsense", "StaticInstancedActorInteractableName", "Prop");
20}
UStaticMeshComponent * StaticMeshComponent

References InteractableName, and StaticMeshComponent.

Member Function Documentation

◆ AddToInstancedRendering()

bool AInstancedActor::AddToInstancedRendering ( )

Add this InstancedActor to Instanced rendering if it wasn't already added.

Returns
True if the InstancedActor was successfully added to Instanced rendering.

Definition at line 74 of file InstancedActor.cpp.

75{
77 {
78 return false;
79 }
80
82 if (InstanceRenderer)
83 {
84 return InstanceRenderer->AddActorToInstancedRendering(this);
85 }
86
87 return false;
88}
bool AddedToInstancedRenderer
bool ShouldUpdateTransformAutomatically
bool AddActorToInstancedRendering(AInstancedActor *InstancedActor)
static AInstancedRenderer * GetInstancedRenderer(const UObject *WorldContextObject)

References AInstancedRenderer::AddActorToInstancedRendering(), AddedToInstancedRenderer, AddToInstancedRenderer, UAgrarsenseStatics::GetInstancedRenderer(), and ShouldUpdateTransformAutomatically.

Referenced by BeginPlay().

◆ BeginPlay()

void AInstancedActor::BeginPlay ( )
overridevirtual

Definition at line 22 of file InstancedActor.cpp.

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}
FTransform PreviousTransform
bool AddToInstancedRendering()

References AddToInstancedRendering(), CustomDepthSetup, PreviousTransform, and StaticMeshComponent.

◆ EndPlay()

void AInstancedActor::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overridevirtual

Definition at line 37 of file InstancedActor.cpp.

38{
39 Super::EndPlay(EndPlayReason);
40
41 if (EndPlayReason != EEndPlayReason::Type::EndPlayInEditor)
42 {
44
46 {
47 StaticMeshComponent->UnregisterComponent();
48 StaticMeshComponent->DestroyComponent();
49 StaticMeshComponent = nullptr;
50 }
51 }
52}
void RemoveFromInstancedRendering(bool EnableStaticMeshComponent=true)

References RemoveFromInstancedRendering(), and StaticMeshComponent.

◆ GetActorID_Implementation()

virtual FString AInstancedActor::GetActorID_Implementation ( ) const
inlineoverridevirtual

Definition at line 219 of file InstancedActor.h.

220 {
221 return ActorID;
222 }

◆ GetActorName_Implementation()

virtual FString AInstancedActor::GetActorName_Implementation ( ) const
inlineoverridevirtual

Definition at line 224 of file InstancedActor.h.

225 {
226 return ActorName;
227 }

◆ GetAllowWorldPositionOffsetDisable()

bool AInstancedActor::GetAllowWorldPositionOffsetDisable ( ) const
inline

Definition at line 173 of file InstancedActor.h.

174 {
176 }
bool AllowWorldPositionOffsetDisable

Referenced by AInstancedRenderer::FindOrAddUniqueMesh().

◆ GetComponentIndex()

int AInstancedActor::GetComponentIndex ( ) const
inline

Definition at line 153 of file InstancedActor.h.

154 {
155 return ComponentIndex;
156 }

◆ GetInstanceEndCullDistance()

int AInstancedActor::GetInstanceEndCullDistance ( ) const
inline

Definition at line 130 of file InstancedActor.h.

131 {
133 }
int InstanceEndCullDistanceInCm

Referenced by AInstancedRenderer::FindOrAddUniqueMesh().

◆ GetInstanceIndex()

int AInstancedActor::GetInstanceIndex ( ) const
inline

Definition at line 158 of file InstancedActor.h.

159 {
160 return InstanceNumber;
161 }

◆ GetInstanceStartCullDistance()

int AInstancedActor::GetInstanceStartCullDistance ( ) const
inline

Definition at line 124 of file InstancedActor.h.

125 {
127 }
int InstanceStartCullDistanceInCm

Referenced by AInstancedRenderer::FindOrAddUniqueMesh().

◆ GetInteractableName_Implementation()

virtual FText AInstancedActor::GetInteractableName_Implementation ( ) const
inlineoverridevirtual

Definition at line 209 of file InstancedActor.h.

210 {
211 return InteractableName;
212 }

◆ GetInteractableWorldTransform_Implementation()

virtual FTransform AInstancedActor::GetInteractableWorldTransform_Implementation ( ) const
inlineoverridevirtual

Definition at line 214 of file InstancedActor.h.

215 {
216 return GetActorTransform();
217 }

◆ GetModelIDString()

FString AInstancedActor::GetModelIDString ( ) const
inline

Definition at line 148 of file InstancedActor.h.

149 {
150 return ModelID;
151 }

◆ GetPreviousTransform()

FTransform AInstancedActor::GetPreviousTransform ( ) const
inline

Definition at line 178 of file InstancedActor.h.

179 {
180 return PreviousTransform;
181 }

◆ GetStaticMeshComponent()

UStaticMeshComponent * AInstancedActor::GetStaticMeshComponent ( ) const
inline

Definition at line 118 of file InstancedActor.h.

119 {
120 return StaticMeshComponent;
121 }

Referenced by AInstancedRenderer::AddActorToInstancedRendering().

◆ GetTypeIDString()

FString AInstancedActor::GetTypeIDString ( ) const
inline

Definition at line 142 of file InstancedActor.h.

143 {
144 return TypeID;
145 }

◆ HasAlternativeMaterial()

bool AInstancedActor::HasAlternativeMaterial ( ) const
inline

Definition at line 163 of file InstancedActor.h.

164 {
165 return AlternativeMaterial;
166 }

Referenced by AInstancedRenderer::FindOrAddUniqueMesh().

◆ InstanceAdded()

void AInstancedActor::InstanceAdded ( int32  CompIndex,
int32  InstanceNum 
)

Notify that this Actor instance has been added to InstancedRenderer. This should only be called from InstancedRenderer.cpp

Definition at line 90 of file InstancedActor.cpp.

91{
92 // Hide StaticMeshComponent Visibility since InstancedRenderer
93 // is now resposible for rendering this Actor's mesh.
94 // Note. StaticMeshComponent is still resposible for collisions.
96 {
97 StaticMeshComponent->SetVisibility(false);
98 StaticMeshComponent->SetComponentTickEnabled(false);
99 }
100
101 ComponentIndex = CompIndex;
102 InstanceNumber = InstanceNum;
104}

References AddedToInstancedRenderer, ComponentIndex, InstanceNumber, and StaticMeshComponent.

Referenced by AInstancedRenderer::AddActorToInstancedRendering().

◆ IsAddedToInstancedRendering()

bool AInstancedActor::IsAddedToInstancedRendering ( ) const
inline

Check if this InstancedActor is already added to Instanced rendering.

Returns
True if the InstancedActor is added to Instanced rendering. false otherwise.

Definition at line 112 of file InstancedActor.h.

113 {
115 }

◆ IsCustomDepthSetup()

bool AInstancedActor::IsCustomDepthSetup ( ) const
inline

Definition at line 168 of file InstancedActor.h.

169 {
170 return CustomDepthSetup;
171 }

Referenced by ATagger::TagActor().

◆ IsTreeActor()

bool AInstancedActor::IsTreeActor ( ) const

Definition at line 130 of file InstancedActor.cpp.

131{
133 {
134 UStaticMesh* Mesh = StaticMeshComponent->GetStaticMesh();
135 if (Mesh)
136 {
137 FString Path = Mesh->GetPathName();
138 if (Path.Contains("Tree"))
139 {
140 return true;
141 }
142 }
143 }
144
145 return false;
146}

References StaticMeshComponent.

Referenced by ADeletionVolume::DestroyOverlappingActors(), and AInstancedRenderer::FindOrAddUniqueMesh().

◆ RemoveFromInstancedRendering()

void AInstancedActor::RemoveFromInstancedRendering ( bool  EnableStaticMeshComponent = true)

Remove this InstancedActor from Instanced rendering if it was added.

Parameters
EnableStaticMeshComponentIf true, enables the StaticMeshComponent after removal.

Definition at line 54 of file InstancedActor.cpp.

55{
57 {
59 if (InstanceRenderer)
60 {
62 }
63 }
64
66
67 if (EnableStaticMeshComponent && StaticMeshComponent)
68 {
69 StaticMeshComponent->SetVisibility(true);
70 StaticMeshComponent->SetComponentTickEnabled(true);
71 }
72}
void RemoveInstance(int32 ComponentIndex, int32 InstanceNumber)

References AddedToInstancedRenderer, ComponentIndex, UAgrarsenseStatics::GetInstancedRenderer(), InstanceNumber, AInstancedRenderer::RemoveInstance(), and StaticMeshComponent.

Referenced by EndPlay().

◆ SetActorIDAndName_Implementation()

virtual void AInstancedActor::SetActorIDAndName_Implementation ( const FString &  NewActorName,
const FString &  NewID 
)
inlineoverridevirtual

Definition at line 234 of file InstancedActor.h.

235 {
236 ActorName = NewActorName;
237 ActorID = NewID;
238 SetAndValidateActorIDAndName(ActorName, ActorID, TWeakObjectPtr<AActor>(this));
239 }
static void SetAndValidateActorIDAndName(FString &ActorName, FString &ActorID, TWeakObjectPtr< AActor > Actor)

◆ SetActorName_Implementation()

virtual void AInstancedActor::SetActorName_Implementation ( const FString &  NewActorName)
inlineoverridevirtual

Definition at line 229 of file InstancedActor.h.

230 {
231 ActorName = NewActorName;
232 }

◆ SetTypeAndModel()

void AInstancedActor::SetTypeAndModel ( const FString &  Type,
const FString &  Model 
)
inline

Set Type and Model strings for this InstancedActor This is used when exporting InstancedActor(s) into JSON files

Definition at line 86 of file InstancedActor.h.

87 {
88 TypeID = Type;
89 ModelID = Model;
90 }

Referenced by UAssetLibrary::SpawnFoliage(), and UAssetLibrary::SpawnProp().

◆ UpdateIndex()

void AInstancedActor::UpdateIndex ( int32  UpdatedIndex)

Update this Actor instance index. This should only be called from InstancedRenderer.cpp

Definition at line 106 of file InstancedActor.cpp.

107{
108 if (UpdatedIndex > InstanceNumber)
109 {
110 return;
111 }
112
114}

References InstanceNumber.

◆ UpdatePreviousTransform()

void AInstancedActor::UpdatePreviousTransform ( const FTransform &  NewTransform)
inline

Updates the 'PreviousTransform' member variable with a new transform.

Parameters
NewTransformThe new transform to be assigned to 'PreviousTransform'.

Definition at line 102 of file InstancedActor.h.

103 {
104 PreviousTransform = NewTransform;
105 }

◆ UpdateTransformAutomatically()

bool AInstancedActor::UpdateTransformAutomatically ( ) const
inline

Definition at line 136 of file InstancedActor.h.

137 {
139 }

◆ UpdateTransformPosition()

void AInstancedActor::UpdateTransformPosition ( )

Updates this InstancedActor Transform location to the InstancedRenderer.

Definition at line 116 of file InstancedActor.cpp.

117{
119 {
120 return;
121 }
122
123 AInstancedRenderer* InstanceRenderer = UAgrarsenseStatics::GetInstancedRenderer(GetWorld());
124 if (InstanceRenderer)
125 {
126 InstanceRenderer->UpdateInstanceTransform(ComponentIndex, InstanceNumber, GetActorTransform());
127 }
128}
void UpdateInstanceTransform(int32 ComponentIndex, int32 InstanceNumber, const FTransform &NewTransform)

References ComponentIndex, UAgrarsenseStatics::GetInstancedRenderer(), InstanceNumber, ShouldUpdateTransformAutomatically, and AInstancedRenderer::UpdateInstanceTransform().

Referenced by UROSCommands::HandleTeleportActorByID().

Member Data Documentation

◆ ActorID

FString AInstancedActor::ActorID
private

Definition at line 247 of file InstancedActor.h.

◆ ActorName

FString AInstancedActor::ActorName
private

Definition at line 244 of file InstancedActor.h.

◆ AddedToInstancedRenderer

bool AInstancedActor::AddedToInstancedRenderer = false
private

◆ AddToInstancedRenderer

bool AInstancedActor::AddToInstancedRenderer = true

◆ AllowWorldPositionOffsetDisable

bool AInstancedActor::AllowWorldPositionOffsetDisable = false

Definition at line 187 of file InstancedActor.h.

◆ AlternativeMaterial

bool AInstancedActor::AlternativeMaterial = false

Definition at line 204 of file InstancedActor.h.

◆ ComponentIndex

int32 AInstancedActor::ComponentIndex = 9999999
private

◆ CustomDepthSetup

bool AInstancedActor::CustomDepthSetup = false
private

Definition at line 261 of file InstancedActor.h.

Referenced by BeginPlay().

◆ InstanceEndCullDistanceInCm

int AInstancedActor::InstanceEndCullDistanceInCm = 46500

Definition at line 196 of file InstancedActor.h.

◆ InstanceNumber

int32 AInstancedActor::InstanceNumber = 9999999
private

◆ InstanceStartCullDistanceInCm

int AInstancedActor::InstanceStartCullDistanceInCm = 45000

Definition at line 193 of file InstancedActor.h.

◆ InteractableName

FText AInstancedActor::InteractableName

Definition at line 207 of file InstancedActor.h.

Referenced by AInstancedActor().

◆ ModelID

FString AInstancedActor::ModelID = "none"
private

Definition at line 259 of file InstancedActor.h.

◆ PreviousTransform

FTransform AInstancedActor::PreviousTransform
private

Definition at line 249 of file InstancedActor.h.

Referenced by BeginPlay().

◆ ShouldUpdateTransformAutomatically

bool AInstancedActor::ShouldUpdateTransformAutomatically = false

Definition at line 200 of file InstancedActor.h.

Referenced by AddToInstancedRendering(), and UpdateTransformPosition().

◆ StaticMeshComponent

UStaticMeshComponent* AInstancedActor::StaticMeshComponent = nullptr

◆ TypeID

FString AInstancedActor::TypeID = "none"
private

Definition at line 257 of file InstancedActor.h.


The documentation for this class was generated from the following files: