Download

Can you avoid the reflection system when the subject is an struct?

In the case where I need to create a struct and avoid UE4 GC at all, controlling (manually) a struct lifetime, removing data from the memory and nullifying the references/pointers without the GC intervention myself. It’s possible to declare a struct without tagging it as an USTRUCT? The compiler keeps warning me that the type is undefined and must be a UCLASS, USTRUCT or UENUM.

Personally, I didn’t find an answer for it.

Thanks! :slight_smile:

Here is the snippet:

 // Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “CoreMinimal.h”
#include “GameFramework/Actor.h”
#include “BlackHoleSkill.generated.h”

class AParticleMovementSpline;
class UMaterialInstanceDynamic;
class UNiagaraComponent;
class UNiagaraSystem;
class UProjectileMovementComponent;
class USphereComponent;
class USplineComponent;

/** Enumaration containing values for possible axis in a Euclidian space */
namespace EAxisSet
{
UENUM()
enum Type
{
X = 0,
Y = 1,
Z = 2,

	XY = 3,
	MinusXY = 4,
	XZ = 5,
	MinusXZ = 6,
	YZ = 7,
	MinusYZ = 8,
	XYZ = 9
};

}

/** Enumaration containing values for possible planes in a Euclidian space */
namespace EPlane {

UENUM()
enum Type
{
	YZ = 1,
	XZ = 2,
	XY = 3
};

}

struct FBlackHoleOrbitData
{
/** Value used to notify that an orbit data was perfectly initialized */
bool OrbitFlag = false;

/** Value used to define the orbit pitch angle */ 
float OrbitPitch;

/** Value used to define the orbit roll angle */	
float OrbitRoll;

/** Value of the elliptic orbit semi major axis */	
float OrbitSemiMajorAxis;

/** Value used to define the orbit yaw angle */	
float OrbitYaw;	
	
float ProportionalityFactor = 0.f;
	
float StretchFactor;

/**
 * Value used to store the angle between the black hole and a orbiting
 * actor, projected in the YZ plane
 */	
float YZAngle;

/**
 * Value used to store the angle between the black hole and a orbiting
 * actor, projected in the XY plane
 */	
float XYAngle;

/**
 * Value used to store the angle between the black hole and a orbiting
 * actor, projected in the XZ plane
 */	
float XZAngle;		

/**
 * The conjugate of the quaternion representing the orientation in
 * the X-axis
 */	
FQuat InversedOrientationX;

/**
 * The conjugate of the quaternion representing the orientation in
 * the Y-axis
 */	
FQuat InversedOrientationY;

/**
 * The conjugate of the quaternion representing the orientation in
 * the Z-axis
 */	
FQuat InversedOrientationZ;

/** Quaternion representing the orientation in the X-axis */	
FQuat OrientationX;

/** Quaternion representing the orientation in the Y-axis */	
FQuat OrientationY;

/** Quaternion representing the orientation in the Z-axis */	
FQuat OrientationZ;
	
FTimerDelegate StretchTimerDelegate;
	
FTimerHandle StretchTimer;
	
uint16 NumPointsToBeSampled = 1;

/** The identification pf the orbit data */	
uint32 OrbitID;		
	
TArray<TWeakObjectPtr<UMaterialInstanceDynamic>> OrbitingActorDynamicMaterialArr;

public:

FBlackHoleOrbitData() {}

~FBlackHoleOrbitData()
{
	for(TWeakObjectPtr<UMaterialInstanceDynamic> DynamicMaterialInstance : 
		OrbitingActorDynamicMaterialArr)
	{
		if(DynamicMaterialInstance.IsValid())
		{
			DestructItem(DynamicMaterialInstance.Get());
			DynamicMaterialInstance = nullptr;
		}
	}		

}

};

UCLASS()
class PRJ_PROJECTILETESTEX_API ABlackHoleSkill : public AActor
{
GENERATED_BODY()

/** The minimun speed that a black hole must have */
UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
float BlackHoleInitialSpeed;

/**
 * Value used to define how much a black hole life span can be 
 * extended
 */
UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
float BlackHoleLifetimeFactor;

/** The maximum speed that a black hole can achieve */
UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
float BlackHoleMaxSpeed;

/** Value used to influence an orbiting actor speed */
UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
float BlackHolePullForce;		

UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
float EllipticalMovementRate;

UPROPERTY(EditDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
float SemiMajorAxisFactor;
	
TArray<TSharedPtr<FBlackHoleOrbitData>> OrbitDataArr;

UPROPERTY()
TArray<int> CollisionTypeArr;

UPROPERTY()
TArray<UPrimitiveComponent*> PreviouslyOverlapppedComponentArr;	

UPROPERTY()
UNiagaraComponent* BlackHoleVFXComp = nullptr;

UPROPERTY(EditDefaultsOnly, Category = "Visual Effects", meta = (AllowPrivateAccess = "true"))
UNiagaraSystem* BlackHoleVFX = nullptr;		

UPROPERTY()
UProjectileMovementComponent* BlackHoleMovementComp = nullptr;

UPROPERTY(VisibleDefaultsOnly, Category = "Properties", meta = (AllowPrivateAccess = "true"))
USphereComponent* BlackHoleGravitationalInfluenceSpace = nullptr;	

void CalculateOrbitOrientation(const FVector& OrbitOrigin, const FBlackHoleOrbitData& OrbitData, FVector& OrbitPosition);

FVector CalculateOrbitPosition(const FVector& OrbitOrigin, FBlackHoleOrbitData& OrbitData);

/**
 * Compares two arrays containing UPrimitiveComponent pointers.
 * @param Arr1 - The array that will be compared to
 * @param Arr2 - The base array that will be used to make the comparison
 * @return Confirms the equality between the arrays
 */
bool Compare(TArray<UPrimitiveComponent*> Arr1, TArray<UPrimitiveComponent*> Arr2);

void DrawPrimaryHelpers(const FVector& BlackHoleLocation);

void DrawSecondaryHelpers(const FVector& BlackHoleLocation, const FVector& OrbitingActorLocation, const FBlackHoleOrbitData& NewOrbitData);

FVector EstimateOrbitPosition(const FVector& OrbitOrigin, const FBlackHoleOrbitData& OrbitData, uint32 AngleMultiplier);

TSharedPtr<FBlackHoleOrbitData> GenerateOrbitData(UPrimitiveComponent* OverlappedComponent);

float GetAngleBetween(const FVector& Vec1, const FVector& Vec2, EPlane::Type ProjectionPlane);

UFUNCTION()
//void UpdateMaterials(uint16& FibonacciTerm, TArray<UMaterialInstanceDynamic*>& DynamicMaterialArr);
void UpdateDisplacementEffect(const FVector& OrbitOrigin, FBlackHoleOrbitData& OrbitData);

public:
// Sets default values for this actor’s properties
ABlackHoleSkill(const FObjectInitializer& ObjectInitializer);

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;	

public:
void MoveInDirection(FVector Direction);

virtual void PostInitializeComponents();	

// Called every frame
virtual void Tick(float DeltaTime) override;

};