Object Destruction & Pooling with C# Composition, Inheritance & Interfaces [Andromedoom Dev Log 5]
Polysthetic
๐พWelcome to the Andromedoom dev logs!
In episode 5, I'm following on from the previous tutorial where we covered object creation at runtime, and focussing on object destruction. This will involve two different methods of destruction, one using Godot's Free() or QueueFree() methods, and one using object pooling using C# generic queue structures. In addition, I will be showing you a comparison of how this behaviour would be implemented using composition vs inheritance, and finally how and why to use C# interfaces.
In the dev log, I will be presenting the city building models I pulled together for the remaining four cities in the Asia-Pacific region: Hong Kong, Shanghai, Seoul, and Tokyo.
I hope you enjoy this video series and stick around for the game's development! ๐
โฑ๏ธ Timestamps: 0:00 Intro 1:00 Summary of the scenes and minor changes 3:52 Scripting - Implementing the destructible class with composition 7:00 Scripting - Destroying projectiles after a certain time 8:56 Scripting - Preparing the alien and setting the projectile collisions 10:55 Scripting - How do we know if objects are destructible? Interfaces. 14:18 Composition vs inheritance 15:35 Scripting - Implementing the destructible class with inheritance 17:39 Scripting - Destroying the buildings/shields 18:40 Changing meshes at runtime for destruction effects 23:00 Object pooling using C# queue data structures 24:10 Scripting - Object pool for projectiles 27:40 Debugging the object pool 28:50 Dynamically setting the pool size 32:33 Conclusions on interfaces, inheritance and extending pooling 36:20 Dev log - The Fossilators! a.k.a Diesel Death Robots. 39:38 Dev log - Model materiality 41:45 Conclusion
๐ป Addenda:
- Note that in my main project, I favoured composition over inheritance for destructible objects. It proved more easily extensible, with inheritance used for other abstract properties i.e. player ships and aliens have super classes for the specific types Alien and Ship, with each alien and ship having its own script that derive from these super classes. The super classes implement Destructible. This greatly reduced the amount of code reuse.
- Yes, I misspelled destructible*.
- Instead of using EnterTree(), you can call RequestReady() on the projectile. This will call the Ready() method again when the projectile re-enters the scene tree.
๐ถ Music tracks from:
- Flitz&Suppe - Yokai
- Provided by Lofi Girl
- Listen: https://fanlink.to/YokaiEP
You can also visit me at: WEBSITE ๐ https://polysthetic.com THREADLESS ๐ถ๏ธ https://polysthetic.threadless.com DRIBBBLE ๐ https://dribbble.com/polysthetic YOUTUBE ๐ฅ https://youtube.com/c/polysthetic AUDIOMACK ๐ผ https://audiomack.com/polysthetic ... https://www.youtube.com/watch?v=ZQ6dpoigV6g
192405206 Bytes