Hi there! I’m having an issue with a plugin I’m using but before I raise a ticket in there, I want to make sure I understand correctly what is the expected behavior for the Unreal editor. The plugin I mentioned is used to enable a sort of global event system and they use a static variable that stores all the event listeners.
What I noticed though, is that between plays in editor (if I play, stop and play again, for example), this variable is being kept, which is keeping listeners from previous sessions as well, which is obviously causing problems. If I close the editor and open it again, it clears everything.
So what I wanted to understand is: is that expected behavior? Shouldn’t static variables be killed when I stop my game session? Or is it some sort of setting or cache maybe?
That is expected behavior, although I can’t speak to whether it is intended behavior, too.
The event handler is a static variable, which means it is created when the application starts (when the plugin is loaded to be more specific) and destroyed when the application closes. So it persists across PIE sessions because the application itself, the editor, is of course not closed and restarted for every PIE session.
The easiest thing you could do is just empty the event listener yourself when you start or end a PIE session.
But since unreal is so big and there’s still a lot I don’t know, I just wanted to confirm: Is that indeed a good place to do it, or would you recommend somewhere else?
It sounds like the right place, but I’ve never worked with that function myself, so I can’t vouch for it. The best place to do this will ultimately depend on your specific game and game design, but for now this is probably good enough.