Unreal handles UStructs as Values or simple Data. Using them as Pointers calls for trouble =)
So I’m not sure if this is a bug or not, I just wanted to check to see if someone knew what was going on.
So I have a blueprint function in c++ with a TArray of a custom UStruct called FBob. So my function looks something like
bool UStaticMeshLibrary::StaticMeshLibrary(TArray<FBob> bob)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::FromInt(bob.Num()));
FBob *temp4 = new FBob;
bob.Add(*temp4);
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::FromInt(bob.Num()));
if (bob.Num()!=0) {GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, FString::FromInt(bob.Num()));}
}
so logically, if the initial bob array had 4 items, then the print sequence should be ‘4,5,5,’. But what’s really bizarre is that the print sequence is ‘4,5,0’. What’s truly astounding about this, is that somehow the compiler realizes bobs size is more than zero and passes me through the conditional, but then immediately after this bob is somehow zero. Can someone please explain to me wtf is going on??
Dont use UStruct Pointers a simple FBob temp = FBob(); is enough. I assume any other odd behavior is resulting from that.
But I can’t create UStructs dynamically without using pointers…
Yeah I have run into problems with garbage collection, but I think I have it figured out now. Unfortunately I do need dynamic allocation, so I’ll just have to work around the quirks.
I appreciate your help!