How to set up a reference to a static level object in a dynamically instantiated actor?

I have a fixed, static object in my level placed in the editor that I want my player-controlled pawns to be able to reference in their C++ code. I would like to set up that reference in the editor.

It doesn’t seem possible to set up those references by deriving the pawn class in BP and setting the object reference as the default value. They just stay as None despite being highlighted when attempting to drag the object to the slot.

So how can I do that without fragile logic like finding the object by name?

Well, if you know that the actor is a singleton, the usual way to do it is to create a public, static function in the singleton object’s class which uses an actor iterator to look for an object of its own class and return itself. (See here: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine ForumsObject%26_Actor_Iterators,_Optional_Class_Scope_For_Faster_Search#Actor_Iterator) You’ll need to pass it a world so it knows where to look, though.

Does this thing have to be an actor, though? There are better ways of doing this in most cases, like with a game singleton. That’s a better way to ensure the object exists without adding magic stuff your level designers need to add to every level just to get them to work.

I totally agree that it doesn’t seem like a great way, but how else would you do that if every level is supposed to have a certain special object (like an exit door for instance) and the level is invalid if it does not have it?