0 votes

Hi,

I'm coming from Unity and I have some issues trying to understand how Godot works with pure storage classes and arrays editable in the editor.

In Unity, classes that can go on object inherits from Monobehaviour but we can create classes that won't inehrit from Mono and that will serve as data holders mainly.

For instance, if I want to make a quiz game, I will make a QuizManager class that inherits from Monobehaviour and that will go on a game object.

I will also create two other classes that won't inherit from Mono, QuestionData and AnswerData and I will make these classes serializable, the answerData will be an array in the QuestionData and the QuestionData will be an array in the QuizManager.

In code this would give something like this :

QuizManager.cs :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class QuizManager : MonoBehaviour
{
    [SerializeField] private QuestionData[] _questionData;
}

QuestionData.cs :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class QuestionData
{
    public string _question;
    public AnswerData[]  _answers;
    public int _correctAnswerID;
}

AnswerData.cs :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class AnswerData
{
    public string _answer;

}

Theses scripts would give the following result in the editor once designer worked on them :

ImageEditor
https://imgur.com/a/9Ydc2b4

Of course at the end there is a system that allows data to be imported from CSV or JSON or else in order to avoid to manually enter these data in the engine but that's another step for another time, for the moment, how do you reproduce a similar architecture in Godot ? Is this something possible ?

Thanks

Godot version Godot 4
in Engine by (12 points)

I believe Resource class may be that thing.
check out some tutorials on them. I found them actually icky to set up, so I prefer to store data in script classes ( which extend Resource anyway) or autoloaded scripts. Main advantage of resources classes is that You can edit them within editors UI.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.