#Unable to make custom resource/class that is editable in editor

1 messages · Page 1 of 1 (latest)

lament mica
#

Hi all, I'm trying to make a custom class that can be edited within the editor. I saw that the Resource class is useful for this, but for some reason when I try to implement it I get "ERROR: Cannot get class 'TestClass'.". Anything simple I'm missing to get this working?

twin saddle
#

Watch “Custom Resources in Godot 4 and How to Use Them” on YouTube—it shows step-by-step how to register a class_name, create the .tres, and avoid the “Cannot get class” error.

lament mica
twin saddle
#

Also, this might be related maybe.

Add to your script:

extends Resource
class_name TestClass

Save it and reload the editor; giving the script a class_name is what registers the custom Resource so Godot can find it.

lament mica
#

Yup

twin saddle
#

Finally

twin saddle
#

For C#: inherit from Resource and add [GlobalClass]:

using Godot;

[GlobalClass] // registers the resource type
public partial class TestClass : Resource { }

Rebuild the project; the editor will now list TestClass as a creatable Resource (perfect for your difficulty-preset array).

#

Going to bed now

#

G’nite

lament mica
#

Apparently creating a brand new script and having it inherit from Resource straight from the get go worked. Not sure why but there we go.

twin saddle
frank ravine
#

A small tip: When using C#, make sure your .cs file is named exactly the same as the class you are trying to make global with [GlobalClass], otherwise godot cannot find it.

lament mica