I’m a week now trying to understand what is going on without success.
I have this piece of code: (most of it comments explaining my issue)
void USomeClass::someFunction(TArray<UBaseA*>& outOthers, UBaseA* initiator, UBaseA* responder)
{
// at this point the inputs to the method are correct and valid (data-wise) the pointed to data
// is not garbage
if (not mIsRequiresOther) return;
const auto manager = GetWorld()->GetGameInstance()->GetSubsystem<UManagerSubsystem>()->getInstance();
checkf(manager != nullptr, TEXT("Couldn't get manager"));
TArray<UBaseA*> possibleOthers = {};
manager->getAllGameObjects(possibleOthers);
// at this point, the possible others is filled with objects as i can see in the debugger, all are valid and correct
for (int32 j = 0; j < possibleOthers.Num(); j++) {
UBaseA* other = possibleOthers[j];
// at this stage few things may happen:
// - data inside other seem ok and not garbage
// - data inside other may seem garbage and invalid as shown below, although if using
// IsValid() or possibleOthers.IsIndexValid(j), all return true and work fine
// 0x00000b65db518cd8 (Name = Illegal name (length > NAME_SIZE)_4294967294,
// Owner = 0x0000000000000000 (Name=???))
// - the most baffling issue is that at the moment the if statement below is executed,
// something becomes garbage
// - responder may show the same illegal name error shown above even though moment
// ago it was fine
// - or all values in the debugger may seem good and absolutely satisfy the if statement,
// but it returns false and then the responder becomes garbage
// - the same could happen to other
if ((initiator->mObjectName != other->mObjectName) && (responder->mObjectName != other->mObjectName)) {
... do something ...
}
}
}
I tried so many things, including using for ranged loop, using IsValid on all possible objects, trying even to refactor the getAllGameObjects() to return array of FNames (mObjectName is FName) instead of objects to make sure nothing is garbage collected for some reason, although it shouldn’t be because all the participating member variables here are UPROPERTY().
I also tried to use other member variable of type int, but it results the same.
Anyone encountered something like this or can think of a reason for that to happen?