Hello, I'm currently working on a dialog system, in which each conversation is a .TRES file with the spoken words, answer options etc. My hope was, that by using .TRES file all the resource managment, loading and so on could be handled by the engine. Now that is true, but I don't seem to quite get the gist on how to instantiate objects of custom classes in my .TRES file. I know that it is possible with "built-in" classes (like Vector3Array, shown in https://docs.godotengine.org/en/stable/development/file_formats/tscn.html#animation). But if I try something similar, the engine shows an error on loading the resource. These are my failed experiments:

  1. Using the constructor .new
    [gd_resource type="Resource" load_steps=2 format=2]
    
    [ext_resource path="res://script/ConversationResource.gd" type="Script" id=1]
    
    [resource]
    script = ExtResource( 1 )
    branches = [ Branch.new("Hello, it is me!", ["One", "Two"]) ]
    2. Using same syntax as in the samples
    [gd_resource type="Resource" load_steps=2 format=2]
    
    [ext_resource path="res://script/ConversationResource.gd" type="Script" id=1]
    
    [resource]
    script = ExtResource( 1 )
    branches = [ Branch("Hello, it is me!", ["One", "Two"]) ]
    Either way the result is the following error: ERROR: poll: res://conversation/uncle_bob.tres:7 - Parse Error: Unexpected identifier: 'Branch'. At: scene/resources/resource_format_text.cpp:592 Here are the corresponding classes:
    extends Object
    
    class_name Branch
    
    export(String) var text
    export(Array, String) var choices
    
    func _init(text: String, choices: Array = []):
    	self.text = text
    	self.choices = choices
    extends Resource
    
    class_name Conversation, "res://icon.png"
    
    export(Array) var branches = []
    At this point I ran out of ideas... Is it even possible to use custom classes out of the box or do I need to write plugins/ResourceLoaders? EDIT: Sorry I'm new to these forums, so I didn't know, that there are two types of posts. Started this as discussion, but it is more of a question. Learned my lesson for the next post :)

@AntonioDell said: EDIT: Sorry I'm new to these forums, so I didn't know, that there are two types of posts. Started this as discussion, but it is more of a question. Learned my lesson for the next post

No problem, It is an easy mistake! If you ever want/need a post changed from a discussion to a question, or vice versa, please let one of us on forum staff know and we can change it for you. I changed this post to question :smile:

5 days later
2 years later