#Easy way to implement something that acts similar to a Unity Struct?

1 messages · Page 1 of 1 (latest)

graceful imp
#

Hello, I am trying to make something similar to structs in unity in the inspector. I want to hold 3 variables (object, string, and float) with the object being something in the scene, so that I can just drag and drop whatever object it is without it needing to be a resource in the file system. Also, I want to have the option to "add element", which would automatically add another set of the 3 variables ready to be stored. I tried using a dictionary, but it seems those don't work with the way I want to implement it. I am trying to use an inner class in the code but it also doesn't seem to work. Perhaps I am missing something that would better benefit me.

For clarity, my goal here is to create a list of outputs based on things that enter a trigger, and making that logic local to the scene object.

class Output:
extends Node
@export var object: Object
@export var signalString : String
@export var delay : float

@export var inspector_test : Array[Output] = []

jaunty dome
#

A Resource

#
class_name PlayerData
extends Resource

@export name
@export score
ocean scaffold
#

If you'd like to have an "add element" button in the inspector, and array should work. Just use:

@export var entries: Array[PlayerData]
jaunty dome
#

Then create the array using @export var array:Array[PlayerData]

graceful imp
#

It doesnt seem to do it with the inner class I made

#

Shouldnt it show 3 sets of variables when I append? And the drop down seems to be of any resource

ocean scaffold
graceful imp
ocean scaffold
# jaunty dome A Resource

Rather than a class, @graceful imp, creat a new script, give it a class_name and an extends. As shown in this message:

graceful imp
#

I see now, I was hoping to store it in the same script, but this will do for now. Thank you!

ocean scaffold
#

No problem. If your all set, add the Solved tag to your post, @graceful imp

jaunty dome
#

Godot does not like typed arrays of non existent classes

graceful imp
#

Okay, after further use I am missing 2 key factors that I was looking for by doing this. When I try to make a variable an object, it says a resource can only be built in a resource, a node, or an enum. And using a node just says Node export is only supported in node derived classes buit the current class inherits resource. If i make a variable a script, I cant store an object or script from the current scene I am editing into the object that is making the array of these resources.

jaunty dome
#

What is the object supposed to be?

graceful imp
#

I was assuming it was any object that has a script. But it has to be in the scene tree, and not referencing the filesystem

#

It has to be in the scene, so I can send a signal to it, and I know that I am referencing that instance in the scene

#

To clarify, when I set object to type of script, it only allows me to either create new gdscript, which seems to do nothing. Or load a script from the filesystem. Nothing in the scenetree.

jaunty dome
#

Did you try NodePath?

graceful imp
#

Always something I overlook, thank you!