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?
#Unable to make custom resource/class that is editable in editor
1 messages · Page 1 of 1 (latest)
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.
In this video we'll learn about Custom Resources in Godot 4. Custom resources are a powerful way to handle data in your projects. Resources are an easy way to save/load data if needed.
Example Project on Github: https://github.com/Una1n/CustomResourcesTutorial
0:00 Intro
0:07 What are Resources
0:23 Resources need Nodes to work
0:42 Resources o...
Cheers 👍
I'm going to be using them to create difficulty presets for my game, so it'll be an array of Difficulty resources. I'm assuming this is the best method for that?
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.
1 sec
Ah
You’re usinh C#
Yup
Finally
Yes — array of Difficulty Resources is the clean way I think.
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
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.
Don’t forget to tag it as solved if you haven’t already, xD
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.
That might have been it actually
A YUUUGE tip