Creating new Resource in the inspector

Godot Version

4.3

Question


you can create some resources from the inspectore like here the world environment. How do i do that for my own scripts?

in my example i have a node that represents a skill (probably should switch that also to a Resource) these skills need a TextureButton to activate. i would like to create the TextureButton directly in the inspector so i dont have another file that laying around.

so i addet this to the code:
grafik
but this just lets my assign a TextureButton thats somewhere in the scene but how do also get the create new option ?

TextureButton is actually a Node, not a Resource, though you can create one the same way with .new()

var button: TextureButton

func _ready() -> void:
    button = TextureButton.new()
    add_child(button)

so the aproch would be to create a Skill scene with a TextureButton as a child and use it as a Template? … by always copying the Template scene for every new skill?

That sounds like the opposite of what you wanted, “so i dont have another file that laying around”

My code sample creates a new TextureButton through code. Maybe you need to give a more explicit example, it sounds like you have a specific problem you want to solve, but are presenting something else.

You can create your own type like WorldEnviroment by having the Script extend from Resource (Thats what I think you want to do). Though about a button in the inspector, i am not aware of any possible way to do that.

1 Like

with file laying around i mean not bundelt so i have to look for it in the Filesystem.

I will try to discribe my problem a bit better. thanks for the help and time in advance :slight_smile:

so basically i need a Template for various skills in my game. the Skills are, at the moment there own nodes with a Script(inherits from my own state_class) which are attached to my State machine.

most States/Skills will need a button to trigger the Skill so each Skill needs a button with its own texture. later skills will also need animations and stuff.

so i would need a template where i could just easily can swap the the texture of the button, the stats of my skills and the animation

i hope it makes sense what iam saying im realy new to game dev and not an experiencend programmer

edit: so my idea after you said i cant add a button as a resource would be to make a template skill scene which has a button as a child( so i can edit the button in the editor) does that makes sense?

1 Like

I think you can get this done with a texture resource that is then applied to a code-generated button. Along with other exports for stats and what not

@export var button_texture: Texure2D

func _ready() -> void:
    var button := TextureButton.new()
    button.icon = button_texture
    add_child(button)
1 Like