0 votes

I have created a custom resource to save data in c#. Therefore I created a script (FirstResource) that inherits from Resource and attached it to an Resource.tres. I did the same with a second resource. All varialbes in those resources are flagged as [Export].

For the FirstResource I then want to have a List of the second resources:

public class FirstResource: Resource
{
  [Export] public List<SecondResource> = new List<SecondResource>();
}

For the second resource:

public class SecondResource: Resource
{
[Export] public int SomeAttribute;
}

Then for manager script:

public class ResManager : Node
{
    public override void _Ready()
    {
        firstRes= (FirstResource)ResourceLoader.Load("pathToFirstResource.tres");
        secondRes= (SecondResource)ResourceLoader.Load("pathToSecondResource.tres");
    }

    public void SaveResources()
    { 
     FirstResource firstResourceInstance = firstRes;

           for(int i ; i < 30 ; i++)
           {
                SecondResource secondResourceInstance = secondRes;
                secondResourceInstance.SomeAttribute = i;
                firstResourceInstance.Add(secondResourceInstance);
           }
    ResourceSaver.Save(pathToSaveResource,firstResourceInstance);
    }

}

But setting variables of the SecondResource does not work, they just remain their initial value. However the saved resource has the second resource attached multiple times in the list but all have initial values not those I have assigned.

Is there anything specific I have to account for when assigning variables to the custom resources.

What did I miss here? I would really appreaciate some help.

Godot version 3.3.4
in Engine by (21 points)
edited by

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 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 webmaster@godotengine.org with your username.