Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event listeners persisting between PIE sessions #22

Open
reisandbeans opened this issue Oct 27, 2021 · 6 comments
Open

Event listeners persisting between PIE sessions #22

reisandbeans opened this issue Oct 27, 2021 · 6 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@reisandbeans
Copy link
Contributor

I noticed that due to the static nature of the default event handler, it's keeping objects in memory between PIE sessions. While I do see some mechanisms in the code to clean up stale listeners, my editor still crashed on some occasions when the game tried to emit events and there were some stale listeners from previous sessions.

I don't know if that's intended behavior or not, but it was happening quite often for me, so I ended up adding another static method to the EventHandler class that will re-instantiate the default event handler (so the old one can be garbage collected), and I call that on the OnStart method of the GameInstance class, which solved the problem for me. That said, would be nice to see an "official" support for hooking this plugin into the game lifecycle to do some clean up

@getnamo
Copy link
Owner

getnamo commented Oct 29, 2021

Ideally your 'bind' action should be balanced with an unbind to control for life cycle of the caller. It's usually enough to add GESUnbindAllEventsForContext to any endplay https://github.com/getnamo/global-event-system-ue4#unbinding.

Simply wrapping it up to end world can still cause you to crash if you e.g. delete the actor before the world ends and so unbinding on e.g. the listener actor/object endplay/destruction like the above is the recommended method.

@getnamo
Copy link
Owner

getnamo commented Oct 29, 2021

It might be possible to enhance this to do auto-unbind automatically e.g. by auto-adding yourself somehow to the destructor of the actor, but I haven't found a clean way to do that yet. Thoughts and code contributions welcome :)

@getnamo getnamo added enhancement New feature or request question Further information is requested labels Oct 29, 2021
@reisandbeans
Copy link
Contributor Author

I have an idea that I'd like to try. I will let you know if it works

@reisandbeans
Copy link
Contributor Author

reisandbeans commented Nov 3, 2021

@getnamo I created an example PR with the idea I mentioned a few days ago, check it out: #23

Feel free to change it, or discard it completely. To be honest, even though I'm experienced an developer, I consider myself too newbie when it comes to unreal and I feel like I don't know what doing most of the time, so I could be in the wrong track here 😅

@getnamo
Copy link
Owner

getnamo commented Nov 3, 2021

It's an interesting approach could be useful for PIE start/re-start. I only wonder if the clear function is guaranteed to call before other begin play functions otherwise bugs could appear from clearing after a few setup calls have already been done. Let me know if your testing finds it always called before begin play.

@reisandbeans
Copy link
Contributor Author

so far it seems to work, but since I was focused on something else, I've done some very superficial testing. I will run some more thorough tests and will let you know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants