Okay on further inspection I don’t think the garbage collection should cause any issues directly
like what I’m doing right now (first case):
template <typename T>
struct FMyStruct {
public:
FMyStruct() {};
FMyStruct(UMyObject* NewMyObj) { MyObj = NewMyObj; };
void SetValue(T NewValue) {
Value = NewValue;
if (MyObj)
MyObj->DoSomething();
}
T GetValue() const { return Value; }
private:
T Value;
UMyObject* MyObj;
};
UCLASS()
class MYPROJECT_API AMyActor : public AActor
{
GENERATED_BODY()
public:
AMyActor(){
SomeObj = CreateDefaultSubobject<UMyObject>(TEXT("SomeObj"));
KeyA = FMyStruct<bool>(SomeObj);
KeyB = FMyStruct<int>(SomeObj);
};
UPROPERTY()
UMyObject * SomeObj;
FMyStruct<bool> KeyA;
FMyStruct<int> KeyB;
};
Is the same as (second case):
UCLASS()
class MYPROJECT_API AMyActor : public AActor
{
GENERATED_BODY()
public:
AMyActor(){
SomeObj = CreateDefaultSubobject<UMyObject>(TEXT("SomeObj"));
};
UPROPERTY()
UMyObject * SomeObj;
UPROPERTY()
bool KeyA;
UPROPERTY()
int KeyB;
UFUNCTION()
virtual void SetKeyA(bool NewKeyA){
KeyA = NewKeyA;
if(SomeObj)
SomeObj->DoSomething()
}
UFUNCTION()
virtual void SetKeyB(int NewKeyB){
KeyB = NewKeyB;
if(SomeObj)
SomeObj->DoSomething()
}
};
so even if in the first case SomeObj
gets garbage collected it will have the same effect as the second case
Correct me if I’m wrong but I think since I’ll always be using FMyStruct
in this manner garbage collection should not be a problem
But if it is, can you give me any example of where this might fail?