Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Display scene with scripted changes in the editor

$
0
0

If I have a sprite or any other predefined node in a scene and change its props in the inspector, I can see the change in the editor immediately. But if I have some programmable changes to the scene (let's say in the _ready() function), they are not shown in the editor and are only visible if I run the project. Is it possible to show such changes in the editor as well?

For instance, I was doing a component which is basically a color palette. It's a horizontal bar of colored squares. It exports an array of Colors, so I can instantiate this component in my scene and set the colors in the inspector. Then in the _ready() method I insert a colored square for each configured color. But it will stay empty unless I run the project.

Is it possible to make my components render some dynamic(programmable) changes in the editor?

This is my palette code:

extends Node2D@export var colors:Array[Color] = []signal color_selected(color:Color)# Called when the node enters the scene tree for the first time.func _ready():    var x = 0    var size = 100    var white_texture = load("res://white_pixel.png")    for clr in colors:        print("Adding color: " + find_color(clr))        var btn = TextureButton.new()        btn.size = Vector2(size,size)        btn.texture_normal = white_texture        btn.stretch_mode = TextureButton.STRETCH_SCALE        btn.modulate = clr        btn.position = Vector2(x, 0)        btn.connect("button_down", color_clicked.bind(btn))        add_child(btn)        x += sizefunc color_clicked(btn:TextureButton):    emit_signal("color_selected", btn.modulate)

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>