Star Generation Revisited

One last thing we wanted to experiment with for Satellite Bash was Godot's MultiMeshInstance2D node. Under the right circumstances Godot's MultiMesh system could drastically speed up rendering. So we wanted to understand how we can use it and what kind of impact we'd see in a simple situation.
Our stars seemed like a good candidate because they're static sprites where we have over 100 instances, which don't move or have any individual logic.
Originally we were just instantiating each star as a Sprite2D from a PackedScene, adding 350 Sprite2Ds to our scene. We switched this over to one MultiMeshInstance2D, and set the mesh to a quad. MultiMeshInstance2D only takes one texture, so we duplicated this and set each to one of the star textures.
At first nothing was showing up and we weren't sure why, but it turned out we simply needed to set the quad size.
Setting colour (which we use for star transparency) was weird, because originally we had set the instance count directly on the MultiMeshInstance2D, but to enable colour we had to set the count to 0. This just meant moving setting the count into the generation script.
The prefabs for the stars actually had different sprite sizes, so we also had to do two different quad sizes before the scaling to get similar results to what we had before.
One downside from this change is we now have exactly 175 of each star type vs spawning a random 350 total stars like we did before. In practice, there isn't really a noticeable difference, so we've left it as it. Otherwise, we could have still randomly picked 350 stars and just used the resulting counts in two different instance counts based on which was picked.
Once everything was working as expected, we compared the original star generation scene to the new scene with Godot's built-in profiler. Overall performance in the star generation scene improved by almost 3x, though realistically we don't think this will have too much impact on the overall game as we don't expect we were rendering limited at this time anyway, but that's something we'd dive into more on a larger project.
But it was a fun way to learn the MultiMesh system!
Here's the new code:
--
Play the Game
- On Wandering Door Games
- On itch.io
As always, the game is open source!
You can find it on our Codeberg.
💜 Love open source projects?
Here are ways you can support us making them!
Get Satellite Bash
Satellite Bash
Defend your tiny planet against various space hazards
Status | Released |
Author | Wandering Door Games |
Tags | Arcade, foss, Godot, Mouse only, Open Source, Singleplayer, Space |
Languages | English |
Accessibility | Configurable controls, Interactive tutorial |
More posts
- Spawn Exclusion Zones26 days ago
- Satellite Orbits33 days ago
- Score Feedback41 days ago
- Enemy Scaling48 days ago
- Star Generation55 days ago
- Satellite Bash - Out Now!58 days ago
- Planet Generation58 days ago
Leave a comment
Log in with itch.io to leave a comment.