I come from a C# background and am making the splash into C++ so my knowledge is quite limited at this stage.
I have been trying to implement a simple TArray by following the dynamic arrays tutorial on the wiki but seem to be encountering a rather silly issue.
In my header file I have a property :
UPROPERTY(EditAnywhere, Category = "General")
TArray<AMyInfo*> MyInfos;
Then, in a function inside my .cpp file I loop all the actors of my type via an iterator as add each of them to the MyInfos TArray.
TActorIterator<AMyInfo>ActorItr(GetWorld());
while (ActorItr)
{
MyInfos.Add(*ActorItr);
++ActorItr;
}
Up to this point I never encounter any errors or problems, so I assume I have not done anything too sinister and all is going to plan.
In another function inside my .cpp file I then want to get a reference to the pointer by doing the following:
// for testing but this will change.
if (MyInfos.IsValidIndex(0))
{
TAutoWeakObjectPtr<AMyInfo> info = TAutoWeakObjectPtr<AMyInfo>(MyInfos[0]);
// No matter what I try this value is always null.
}
The code runs without error, however no matter what I try the value of info is always null. I have tested grabbing the object when I loop the actors and the object is definitely there.
My mind keeps pulling me back to my C# experience and I cannot help but wonder whether I am supposed to initialise the TArray property somewhere?
Any suggestions would be greatly appreciated.