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)
 
void SetUpdateTransformAutomatically (bool UpdateAutomatically)
 
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#if WITH_EDITOR
79 UE_LOG(LogTemp, Warning, TEXT("InstancedActor.cpp: Already added to instanced rendering."));
80#endif
81 return false;
82 }
83
85 {
86#if WITH_EDITOR
87 UE_LOG(LogTemp, Warning, TEXT("InstancedActor.cpp: %s Actor is not being renderered by UInstancedStaticMeshComponent. If you did not mean to do this, make sure AddToInstancedRenderer is set to true in blueprint."), *this->GetName());;
88#endif
89 return false;
90 }
91
93 if (InstanceRenderer)
94 {
95 return InstanceRenderer->AddActorToInstancedRendering(this);
96 }
97
98 return false;
99}
bool AddedToInstancedRenderer
bool AddActorToInstancedRendering(AInstancedActor *InstancedActor)
static AInstancedRenderer * GetInstancedRenderer(const UObject *WorldContextObject)

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

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 226 of file InstancedActor.h.

227 {
228 return ActorID;
229 }

◆ GetActorName_Implementation()

virtual FString AInstancedActor::GetActorName_Implementation ( ) const
inlineoverridevirtual

Definition at line 231 of file InstancedActor.h.

232 {
233 return ActorName;
234 }

◆ GetAllowWorldPositionOffsetDisable()

bool AInstancedActor::GetAllowWorldPositionOffsetDisable ( ) const
inline

Definition at line 180 of file InstancedActor.h.

181 {
183 }
bool AllowWorldPositionOffsetDisable

Referenced by AInstancedRenderer::FindOrAddUniqueMesh().

◆ GetComponentIndex()

int AInstancedActor::GetComponentIndex ( ) const
inline

Definition at line 160 of file InstancedActor.h.

161 {
162 return ComponentIndex;
163 }

Referenced by AInstancedRenderer::UpdateInstancedActors().

◆ GetInstanceEndCullDistance()

int AInstancedActor::GetInstanceEndCullDistance ( ) const
inline

Definition at line 137 of file InstancedActor.h.

138 {
140 }
int InstanceEndCullDistanceInCm

Referenced by AInstancedRenderer::FindOrAddUniqueMesh().

◆ GetInstanceIndex()

int AInstancedActor::GetInstanceIndex ( ) const
inline

Definition at line 165 of file InstancedActor.h.

166 {
167 return InstanceNumber;
168 }

Referenced by AInstancedRenderer::UpdateInstancedActors().

◆ GetInstanceStartCullDistance()

int AInstancedActor::GetInstanceStartCullDistance ( ) const
inline

Definition at line 131 of file InstancedActor.h.

132 {
134 }
int InstanceStartCullDistanceInCm

Referenced by AInstancedRenderer::FindOrAddUniqueMesh().

◆ GetInteractableName_Implementation()

virtual FText AInstancedActor::GetInteractableName_Implementation ( ) const
inlineoverridevirtual

Definition at line 216 of file InstancedActor.h.

217 {
218 return InteractableName;
219 }

◆ GetInteractableWorldTransform_Implementation()

virtual FTransform AInstancedActor::GetInteractableWorldTransform_Implementation ( ) const
inlineoverridevirtual

Definition at line 221 of file InstancedActor.h.

222 {
223 return GetActorTransform();
224 }

◆ GetModelIDString()

FString AInstancedActor::GetModelIDString ( ) const
inline

Definition at line 155 of file InstancedActor.h.

156 {
157 return ModelID;
158 }

◆ GetPreviousTransform()

FTransform AInstancedActor::GetPreviousTransform ( ) const
inline

Definition at line 185 of file InstancedActor.h.

186 {
187 return PreviousTransform;
188 }

Referenced by AInstancedRenderer::UpdateInstancedActors().

◆ GetStaticMeshComponent()

UStaticMeshComponent * AInstancedActor::GetStaticMeshComponent ( ) const
inline

◆ GetTypeIDString()

FString AInstancedActor::GetTypeIDString ( ) const
inline

Definition at line 149 of file InstancedActor.h.

150 {
151 return TypeID;
152 }

◆ HasAlternativeMaterial()

bool AInstancedActor::HasAlternativeMaterial ( ) const
inline

Definition at line 170 of file InstancedActor.h.

171 {
172 return AlternativeMaterial;
173 }

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 101 of file InstancedActor.cpp.

102{
103 // Hide StaticMeshComponent Visibility since InstancedRenderer
104 // is now resposible for rendering this Actor's mesh.
105 // Note. StaticMeshComponent is still resposible for collisions.
107 {
108 StaticMeshComponent->SetVisibility(false);
109 StaticMeshComponent->SetComponentTickEnabled(false);
110 }
111
112 ComponentIndex = CompIndex;
113 InstanceNumber = InstanceNum;
115}

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 119 of file InstancedActor.h.

120 {
122 }

◆ IsCustomDepthSetup()

bool AInstancedActor::IsCustomDepthSetup ( ) const
inline

Definition at line 175 of file InstancedActor.h.

176 {
177 return CustomDepthSetup;
178 }

Referenced by ATagger::TagActor().

◆ IsTreeActor()

bool AInstancedActor::IsTreeActor ( ) const

Definition at line 158 of file InstancedActor.cpp.

159{
161 {
162 UStaticMesh* Mesh = StaticMeshComponent->GetStaticMesh();
163 if (Mesh)
164 {
165 FString Path = Mesh->GetPathName();
166 if (Path.Contains("Tree"))
167 {
168 return true;
169 }
170 }
171 }
172
173 return false;
174}

References StaticMeshComponent.

Referenced by ADeletionVolume::DestroyOverlappingActors().

◆ 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 241 of file InstancedActor.h.

242 {
243 ActorName = NewActorName;
244 ActorID = NewID;
245 SetAndValidateActorIDAndName(ActorName, ActorID, TWeakObjectPtr<AActor>(this));
246 }
static void SetAndValidateActorIDAndName(FString &ActorName, FString &ActorID, TWeakObjectPtr< AActor > Actor)

◆ SetActorName_Implementation()

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

Definition at line 236 of file InstancedActor.h.

237 {
238 ActorName = NewActorName;
239 }

◆ 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::SpawnProp().

◆ SetUpdateTransformAutomatically()

void AInstancedActor::SetUpdateTransformAutomatically ( bool  UpdateAutomatically)

Definition at line 141 of file InstancedActor.cpp.

142{
144 {
145 // No change, return
146 return;
147 }
148
149 ShouldUpdateTransformAutomatically = UpdateAutomatically;
150
151 AInstancedRenderer* InstanceRenderer = UAgrarsenseStatics::GetInstancedRenderer(GetWorld());
152 if (InstanceRenderer)
153 {
155 }
156}
bool ShouldUpdateTransformAutomatically
void AddOrRemoveActorFromAutomaticTransformUpdates(bool Add, AInstancedActor *InstancedActor)

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

◆ UpdateIndex()

void AInstancedActor::UpdateIndex ( int32  UpdatedIndex)

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

Definition at line 117 of file InstancedActor.cpp.

118{
119 if (UpdatedIndex > InstanceNumber)
120 {
121 return;
122 }
123
125}

References InstanceNumber.

Referenced by AInstancedRenderer::RemoveInstance().

◆ 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 109 of file InstancedActor.h.

110 {
111 PreviousTransform = NewTransform;
112 }

Referenced by AInstancedRenderer::AddOrRemoveActorFromAutomaticTransformUpdates(), and AInstancedRenderer::UpdateInstancedActors().

◆ UpdateTransformAutomatically()

bool AInstancedActor::UpdateTransformAutomatically ( ) const
inline

Definition at line 143 of file InstancedActor.h.

144 {
146 }

Referenced by AInstancedRenderer::AddActorToInstancedRendering().

◆ UpdateTransformPosition()

void AInstancedActor::UpdateTransformPosition ( )

Updates this InstancedActor Transform location to the InstancedRenderer.

Definition at line 127 of file InstancedActor.cpp.

128{
130 {
131 return;
132 }
133
134 AInstancedRenderer* InstanceRenderer = UAgrarsenseStatics::GetInstancedRenderer(GetWorld());
135 if (InstanceRenderer)
136 {
137 InstanceRenderer->UpdateInstanceTransform(ComponentIndex, InstanceNumber, GetActorTransform());
138 }
139}
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 254 of file InstancedActor.h.

◆ ActorName

FString AInstancedActor::ActorName
private

Definition at line 251 of file InstancedActor.h.

◆ AddedToInstancedRenderer

bool AInstancedActor::AddedToInstancedRenderer = false
private

◆ AddToInstancedRenderer

bool AInstancedActor::AddToInstancedRenderer = true

Definition at line 197 of file InstancedActor.h.

Referenced by AddToInstancedRendering().

◆ AllowWorldPositionOffsetDisable

bool AInstancedActor::AllowWorldPositionOffsetDisable = false

Definition at line 194 of file InstancedActor.h.

◆ AlternativeMaterial

bool AInstancedActor::AlternativeMaterial = false

Definition at line 211 of file InstancedActor.h.

◆ ComponentIndex

int32 AInstancedActor::ComponentIndex = 9999999
private

◆ CustomDepthSetup

bool AInstancedActor::CustomDepthSetup = false
private

Definition at line 268 of file InstancedActor.h.

Referenced by BeginPlay().

◆ InstanceEndCullDistanceInCm

int AInstancedActor::InstanceEndCullDistanceInCm = 46500

Definition at line 203 of file InstancedActor.h.

◆ InstanceNumber

int32 AInstancedActor::InstanceNumber = 9999999
private

◆ InstanceStartCullDistanceInCm

int AInstancedActor::InstanceStartCullDistanceInCm = 45000

Definition at line 200 of file InstancedActor.h.

◆ InteractableName

FText AInstancedActor::InteractableName

Definition at line 214 of file InstancedActor.h.

Referenced by AInstancedActor().

◆ ModelID

FString AInstancedActor::ModelID = "none"
private

Definition at line 266 of file InstancedActor.h.

◆ PreviousTransform

FTransform AInstancedActor::PreviousTransform
private

Definition at line 256 of file InstancedActor.h.

Referenced by BeginPlay().

◆ ShouldUpdateTransformAutomatically

bool AInstancedActor::ShouldUpdateTransformAutomatically = false

Definition at line 207 of file InstancedActor.h.

Referenced by SetUpdateTransformAutomatically(), and UpdateTransformPosition().

◆ StaticMeshComponent

UStaticMeshComponent* AInstancedActor::StaticMeshComponent = nullptr

◆ TypeID

FString AInstancedActor::TypeID = "none"
private

Definition at line 264 of file InstancedActor.h.


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