Using Events... Properly
Here are a few things about our game.
1. We use stand alone levels that are linked by loading one scene from another. 2. We have a "Core" game object that holds everything needed for each level. However, we are not using DoNotDestroyOnLoad. So each level uses its own "Core" game object. 3. We use C# events to link scripts together.
After working on this game for a month we were pretty sure we had everything working. Each level was playable and had all of the features and UI that we wanted. The last day of the jam we were setting up the final levels and putting in the order to load them. After figuring out (finally) that we had to turn off compression for HTML build:
Project Settings -> Player -> WebGL -> Publishing Settings -> Compression Format -> change to Disabled.
We started to test the game on the Itch page and found that the first level worked perfectly, but the next level didn't restart and many of the sounds didn't work. After racking our brains for a few hours (and a good night sleep) upon waking we wondered if possibly it was the events.
After looking closer into it, it turns out we were not UN-subscribing from our events! This was causing the menus to not work properly and all other issues. Luckily we were allowed to add bug fixes, so we quickly uploaded ALL events to unsubscribe OnDestroy. After uploading this new build almost all of our bugs were fixed and we now had a playable game!
Note: We used singletons, but many of the events were set up as static events. If you use a static event, it will linger long after the game object has been destroyed due to it not being an instance. Static events are nice because you don't need to use a singleton, however, there are two main issues:
1. Static events cannot be used for game objects where there are more than one instance. Example: if you have a static event for when you do damage to an enemy, this event won't know which enemy it is damaging and will apply that damage to ALL enemies. So only use static when there is only one of them, like an GameManager.
2. You NEED to unsubscribe from ALL static events.
Thanks for reading!
Julian
Files
Get Goin' Nuts!
Goin' Nuts!
3D side scrolling platformer
Status | Released |
Authors | Draekdude, alexepton, BeachBlock Games, ghost_n_the_cog |
Genre | Platformer |
Leave a comment
Log in with itch.io to leave a comment.