Download the instancing project: click here
I’ve repeated the term “instancing” a few times in the series so far, to introduce you to it. It’s something you’ll do all the time working in a game engine, probably without knowing it.
In this lesson, we finally get to experiment with it and see what it does for us.
The key takeaways are that:
- You can create reproductions of a scene (instances) to your heart’s content. Okay, I’ve insisted enough on that.
- By default, every instance replicates the scene’s defaults, so if you change the scene, every instance updates accordingly.
- You can change a property on one instance which will override the scene’s default (that is to say, replace it).
The ball’s a basic and visual example, but these features are key to master.
For example, say you design a simple health bar. You could create an instance of it and change the bar’s length and color for energy or mana.
In that, instances are Godot’s most powerful tool to reuse code and save time in your projects. Something you’ll see as you create more and more complex projects.
Another tool to reuse code is inheritance, and has to do with scripts. We won’t focus on it in this series, although you’ll get to use it.
In Godot, you can use inheritance both with scripts and scenes (although I don’t recommend using scene inheritance, which currently has some limitations).
GDQuest founder. Courteous designer with a taste for Free Software. I promote sharing and collaboration.