AddReferencedObjects not getting called in viewport client

I’m working on a custom viewport client, which has a bunch of UObjects it creates with ConstructObject. Since it’s not a UCLASS itself, I can’t use a property.

It does override AddReferencedObjects() and does what it needs to do, but in trying to make sure it’s solid I’ve noticed through the debugger that it never actually CALLS it.

I can open the editor that uses it, and everything works just fine, but the overridden method never gets called. Is there supposed to be a manual call to it somewhere?

What is the mechanism with which a custom viewport client gets its AddReferencedObjects() method called? I see in UEditorEngine::AddReferencedObjects that it goes through AllViewportClients and calls AddReferencedObjects(), but I assume there’s a registration step there.

What base class are you using? Did you append the ‘override’ keyword to your method declaration, to ensure you are in fact overriding something?

Since you didn’t really provide much information, it was the obvious place to start. The mechanism comes through the base class, I’m assuming it’s FEditorViewportClient, which derives from FGCObject, which defines the virtual function in question. This class registers itself with garbage collection on construction, so there is no need to manually register or call the method - if an instance of your class exists, then its AddReferencedObjects should be invoked whenever the GC runs. If it’s not, I suspect the cause may be this bug report that I recently opened. Check if one of your copy constructors is being invoked at some stage.

Thanks, but no newbie level help needed on this one. :slight_smile:

Ah that makes a lot more sense now. I had thought the method was getting called at startup, but if it’s getting called at GC time that makes much more sense.

That said, looking through the source I see at least one manual call. STextureEditorViewport::AddReferencedObjects() manually calls its ViewportClient’s AddReferencedObjects() method. I’m guessing this is a bug.

Thanks for the help!

Yeah, interesting. My understanding of this is based only on looking through the engine code, so I’m not 100%, but that certainly looks like a bug to me. Or anyway unnecessary - I doubt calling it manually would have any adverse effects.