Hello!

I'm a longtime programmer and hobbyist game developer. For years I've been building up games "from scratch," but recently I found Godot and I've really enjoyed the tools it gives.

One thing I've noticed is a lot of my games start with some similar logic. Even if I later customize it, it's likely that, for example, in a 2D game I might want an Area2D that can be moved with the arrow keys, or one that I can click and drag around. And I usually add an "Escape to quit" function pretty early on for my root scene, and later expand it to pop up a little context menu with a quit option.

The thing is, I get tired of writing the same thing over and over, even when it's simple. After all, that's why I'm using Godot and not writing the games from scratch like I used to. But, I also usually don't like to take a large system like Top-Down Action RPG Template and get it into the form I want. I'd rather build up from small, reusable pieces.

So, I think I'm going to try out writing some nodes that package the logic I find myself reimplementing. They'd be useful for prototyping, not so much in a final game where you'd surely want more customized and specific logic.

I haven't been able to find evidence of anyone having done this before, but I'd be very interested if there are any I'm missing! I'd much rather use someone else's.

If I do write these myself, I'm curious if anyone would be interested? I know to some extent the best thing to do is make some and upload them to the Asset Library and see how they do, but I'll be more motivated if I hear there's interest ahead of time.

Just to give something concrete, here's a trivial example. I'll also note that my employer demands that any code I share like this be copyrighted to them and licensed with Apache 2, so if any of that will be a problem for you, please be aware!

Example: Quit Node

Name: QuitNode.tscn
Usage: Add an instance to the "main" scene, such as the one started by F5, or that you call get_tree().change_scene() on.

QuitNode.gd:

# Copyright 2022 Google LLC.
# SPDX-License-Identifier: Apache-2.0
extends Node2D

func _input(event):
  if event.is_action_pressed("ui_cancel"):
    get_tree().quit()

(Again, this is very simple, and many cases would likely need to do some unusual things, like directly adjust get_parent().position in order to work, but again, the idea is to make tools that help with the initial prototyping, and so they should be easy to add and easy to replace later.)

Thanks for reading!

  • synthnostate replied to this.
  • this sounds great.
    i will make the reusable pieces that i need for myself, because of the learning effect.
    but having them pre-made will be useful for a lot of people.

    this is such a great concept that it's already been done.
    for example there are many game jam templates, each one is a combined game architecture template and menu system, for making the actual game instead of worrying about the game architecture and menus.
    and my favorite Godot add-on (as of June 2023) is my responsive UI plugin, it just adds a few nodes that

    • are especially tedious to recreate from scratch every time
    • should work (almost) the exact same way in every project
    • i need for creating responsive UI

    this sounds great.
    i will make the reusable pieces that i need for myself, because of the learning effect.
    but having them pre-made will be useful for a lot of people.

    this is such a great concept that it's already been done.
    for example there are many game jam templates, each one is a combined game architecture template and menu system, for making the actual game instead of worrying about the game architecture and menus.
    and my favorite Godot add-on (as of June 2023) is my responsive UI plugin, it just adds a few nodes that

    • are especially tedious to recreate from scratch every time
    • should work (almost) the exact same way in every project
    • i need for creating responsive UI

    epw I'll also note that my employer demands that any code I share like this be copyrighted to them and licensed with Apache 2, so if any of that will be a problem for you

    Yeah that's a problem. Snippets really need to be public domain so people can simply copy them without worrying about licenses.

    So, good idea but someone else should do it. Also, most open-source projects use other licenses so you can't really contribute to much of anything as long as you're under that contract. Maybe they'd drop it if you just ask.

    Thanks, both!

    Sosasees: Interesting! I hadn't looked for any of those in particular. It also makes sense that people often wouldn't want to use them in order to learn instead, I completely get that logic.

    synthnostate: Thanks for the warning, though I'm not sure it's quite like you say. It looks like the majority of items in the asset library (about 1600/1900) are MIT-licensed, which is pretty close to Apache 2. I will say admittedly that there are only about 15 that are Apache 2 licensed, but I'd be surprised if that's actually due to material differences between them.

    An interesting side note is that many IP lawyers claim that individuals literally cannot put things into the public domain, and saying "This is in the public domain" is legally meaningless (see "The Problem" on Creative Common's CC0 page.) This is irrelevant to most people, but companies, even small ones, seem to frequently care about it. I also note about 100 projects labeled CC0 in the Asset Library, and it looks like most are non-code.

    Finally, I am thankfully allowed to contribute to most open-source projects that have any of the standard licenses, though I do like to check with the owners first.

    This is all a longwinded way to say, I'll give it a shot! And if people like it but not the license, they are always free to be inspired to make their own versions, I won't be upset.

    Code snippets are different from assets like add-ons, music and graphics.

    For a code snippet, people probably don't want to deal with keeping track of copyrights and licensing.

    This forum is full of code snippets. I've never seen anyone post a code snippet here and attach a license to it. It's taken for granted that there are no restrictions on usage.

    you probably won't find any code marked as CC0 because as far as I understand creative commons and code don't really get along well, legally, so most people would have that marked as MIT license (closest thing I know of to CC0 for software) but then given your replies so far I have a hunch you might already know that.

    I actually intend to make something similar myself in the future, with my first goal being an "FPS pack" that gives you all the nodes you need to make a retro shooter without having to touch code much at all.