Download

FindObject works on first PIE, fails on second

I’ve been working on a custom saving/loading system, and I’m running into a strange problem. During the load process, I use FindObject to find the Outer from a PathName written to file when re-instantiating saved objects. This worked fine for saving levels and their actors.

The SaveGame used to be in the PlayerController and load was called on BeginPlay(), but that wasn’t going to work very well for changing levels, so I moved it to the GameInstance. I originally tried calling the load function in GameInstance::Init(), but it failed to find the GameInstance every time from there. I figured it must be too early and the GameInstance wasn’t done initializing so it would never find it, so I moved the call to GameInstance::OnStart(). It works fine the first time I run PIE, but if I hit stop and run PIE again, FindObject fails to find the GameInstance.

Is this a bug or is the GameInstance just not guaranteed to be available, yet, at that point?

It’s not a bug and it’s not what you’re thinking.
Every time you play, the instantiated classes have different names.

Well, you’re right in this case, apparently. The GameInstance name is GameInstanceBP_C_0 the first PIE run and GameInstanceBP_C_1 the second time. If I restart the editor every time, it’s always GameInstanceBP_C_0. I was saving all kinds of random editor objects when I was first working on this and multiple PIE runs was never a problem, but I guess GameInstance just wants to be annoying. Thanks for pointing me in the right direction, never thought to check the name because I haven’t seen anything else do that.