TObjectIterator filter out GEN_VARIABLE

I’m iterating over all instances of a component type from an Actor’s code using the following code:

for (TObjectIterator<UMyComponent> iter; iter; ++iter)
{
    if (iter->GetWorld() == GetWorld())
    {
        myComp = *iter;

        if (myComp!= nullptr && myComp->HasBeenCreated())
        {
           //DO STUFF
        }
    }
}

The reason I use test for HasBeenCreated() is to filter out instances of my component that Unreal automatically created with a GEN_VARIABLE suffix. I tried using the RF_WasLoaded flag on the iterator which works but that also sometimes filters out the component that is actually in an object placed in my map.

Am I missing something here or is that a proper way of filtering out those GEN_VARIABLE instances? Are those GEN_VARIABLE instances also there in the shipping game?

Any help or clarification on this would be useful.

Thanks!

If you want to filter out GEN_VARIABLE objects, instead of using the RF_WasLoaded flag, try ignoring objects that has the RF_ArchetypeObject flag.

if (myComp!= nullptr && myComp->HasAnyFlags(RF_ArchetypeObject) == false)
{
    //DO STUFF
}