Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Almost didn't make it

My day kinda slipped away from me. But here I am, working on things. Today I'm doing a little bit of cleanup. 

My object pooling is great (is it? It's actually super-simple), but I was getting warnings in the console about the spawned objects being destroyed. Didn't wanna leave any memory leaks in there, so I decided now was the time to address it, before I get too far and forget or something.

The solution was actually pretty simple, although I did get it wrong at first. 

My first approach was an object that lives through the entirety of the game, from the main menu on. It would hold a list of objects that had been instantiated and destroy them when the scene changed. Unfortunately, trying to trigger an event on scene change with Visual Scripting wasn't exactly easy. I couldn't bother to take the time to figure it out, so I went with another approach.

I took that same object, and instead of keeping it alive during the scene change, it would be destroyed with everything else. Then, I could just activate the On Destroyed node, and iterate through the list of instantiated objects to destroy them. I just have to make sure to drop this little buddy in any scene that instantiates anything (which is just about every scene probably).

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.