Editor Plugin Loveliness

Godot Version

4.4.1

So I coded a building generator plugin. It can create houses of any stories, add X amount of 4 types of windows, it can instantiate stairs to get to the floors, it has a bunch of different kinds of roofs, it allows for setting of different kinds of wall, roof, floor textures, it can add a foundation and a front stoop, it adds doors. It’s working great and allowed me to iterate quickly in building out my world.

The plugin takes input from a dock and generates the building in the 3d viewport and everything appears over on the left scene and I can save it just fine.

As I coded it I understood that I had to make all of the children the scene root owner. Early on I would get crazy errors about duplicate node names, but they didn’t really hurt anything but my pride because everything worked fine in-game.

I got annoyed with them and was able to get rid of them by adding stupid functions to rename all of my node names down through the hiearchy. This was kinda painful because I’m instantiating many stairs and many windows and these scenes obviously had similar names window_pane1, window_pane2, muntin1, muntin2, etc. So I said screw it and did it and the errors are gone now. I even had to namespace the stupid collision shapes.

Was there a better way to do this?

Oh just a little screenshot to show my lovely houses

And inside:

2 Likes

When I’ve had to deal with something like this in the past, usually what I’ve done is created a set of naming functions. Maybe something like:


var NameIndex: Array = []

func add_floor() -> int:
    NameIndex.append({}) # Add an empty dictionary.
    return NameIndex.size()

func property_name(level: int, property: String) -> String:
    if level > NameIndex.size(): return "oob_%s" % property # Shouldn't happen?

    var lvl_dict = NameIndex[level]
    if lvl_dict.has(property): lvl_dict[property] += 1
    else:                      lvl_dict[property]  = 1
    return "%s_%d_%d" % [property, level, lvl_dict[property]]

func stair_name(level: int) -> String:
    return property_name(level, "stair")

func window_name(level: int) -> String
    return property_name(level, "window")

[...]

That doesn’t solve everything, of course; you’d have to decide what to do about the case where you have (say) 11 windows on a level and someone deletes the 5th one. Though it doesn’t matter if you don’t require the final result to have contiguously numbered things.

The question of how deleting one of the middle levels would work is left as an exercise to the reader. :slight_smile:

Okay thanks, just didn’t want to be doing something crazy when there was a better way. Yeah I keep tracking of the windows when they spawn; they self-register so I really don’t care what they are named just as long as the errors in the editor stop spamming me. :stuck_out_tongue: