0 votes

I want to do some of my level generation automatically, so that I don't have to manually position my nodes in my level scenes when I'm designing levels in the editor.

So, for example, suppose I have my Level.tscn open in the editor and I want to run a script which instances my Wall.tscn many times and places the instances at regular intervals.

Here's an example of the script:

var wall_scene = load("res://Wall.tscn")
for n in range(100):
    var wall = wall_scene.instance()
    wall.global_position.y = 0
    wall.global_position.x = n * 64

Suppose I then wanted to save the level as a scene, with the walls now as children.

I know I can run this script in the _ready() function of my Level, but I don't want to run it on the instancing of my level. I want to run it so that the Walls appear in the editor.

How can I do this kind of meta scripting?

in Engine by (1,589 points)

If you make your code a tool, then change the owner of your wall nodes to the root node of Level, it will show up in the editor tree. Of course every time you run it, you might get duplicates of walls.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.