Reference with ID could not be found - Nested Scriptable Objects

Discussion and help for Easy Save 3
Post Reply
Tmoua96
Posts: 3
Joined: Tue Jan 17, 2023 7:02 am

Reference with ID could not be found - Nested Scriptable Objects

Post by Tmoua96 »

Hi,

My main inquiry is at the bottom. EasySave has been making development much easier but I'm currently running into this warning about references not being found. I technically already have the problem solved which turned out to be me needing to add my references to the manager. I can't find the post that mentioned this anymore but the issue may be because the reference is too deep even though it's referenced in the EquipmentManager component. I seem to be able to save and load completely fine initially but when I reload the scene or exit and enter play mode again, the loading results in the warning and a null reference being returned, unless I have already added my EquipmentData reference to the ES3 manager.

These are small bits of the main classes. Use is an abstract class inheriting scriptable object. Technically here, I will have an inventory component with items where I can 'Use' an item. The item will have a reference to an EquipUse type which will then have a reference to an EquipmentData. I feel like it should be getting referenced in the scene but maybe I'm not understanding something correctly. In case there's any relevance, I'll also mention that I create a new array that gets passed into a class called SaveData which then gets saved using ES3.

Code: Select all

public class EquipmentManager : MonoBehaviour, ISaveable
{
    [SerializeField]
    private List<EquipmentData> equipment = new();
    // ...Equip/Unequip methods
    public void Equip(EquipmentData data) { ... }
}

Code: Select all

[CreateAssetMenu(menuName = "Item System/Item")]
public class ItemData : SerializedScriptableObject
{
    // ...id, name, etc
    private Use[] uses;
    public Use[] Uses => uses;
}

Code: Select all

[CreateAssetMenu(fileName = "Use_Equip_New", menuName = "Use Action/Item/Equip")]
public class EquipUse : Use
{
    [SerializeField]
    private EquipmentData equipmentData;

    public override void UseEffect(MonoBehaviour user)
    {
        if (user.TryGetComponent<EquipmentManager>(out var manager))
            manager.Equip(equipmentData);
    }
}

Code: Select all


[CreateAssetMenu(fileName = "EquipmentData_New", menuName = "Item System/Item/Equipment/Equipment Data")]
public class EquipmentData : SerializedScriptableObject
{
    [SerializeField]
    private ItemData item;
    [SerializeField]
    private Dictionary<StatData, float> statBonuses = new();
    [SerializeField]
    private EquipmentType equipmentType;
    
    // ...public getters
}
I'm looking to see if there's any way to make this process easier than manually going through and adding each scriptable object reference to the ES3 manager. Right now, I'm considering re-architecting my code if it's necessary. Any solutions will be appreciated.

Thanks,
Tommy
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Reference with ID could not be found - Nested Scriptable Objects

Post by Joel »

Hi Tommy,
I can't find the post that mentioned this anymore but the issue may be because the reference is too deep even though it's referenced in the EquipmentManager component
You can try modifying the CollectDependenciesDepth to a higher number if you feel you don't have enough depth. This can be found on line 21 of Assets\Plugins\Easy Save 3\Scripts\ES3ReferenceMgrBase.cs. We keep this at a default of 3 as we've found that this is the maximum depth more complex projects can handle before significant slowdown occurs, so I recommend incrementing this one step at a time.
I'm looking to see if there's any way to make this process easier than manually going through and adding each scriptable object reference to the ES3 manager. Right now, I'm considering re-architecting my code if it's necessary. Any solutions will be appreciated.
It wouldn't be possible for Easy Save to do this automatically because it wouldn't have any knowledge of what ScriptableObjects you want to add to the manager. However, you could create an Editor script which automatically adds the ScriptableObjects to the manager. You can add a reference to the manager of the currently active scene using ES3ReferenceMgr.Current.Add().

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Tmoua96
Posts: 3
Joined: Tue Jan 17, 2023 7:02 am

Re: Reference with ID could not be found - Nested Scriptable Objects

Post by Tmoua96 »

Thank you, Joel. I decided to try changing the CollectDependenciesDepth first because I'm not as familiar with editor scripting. I changed the value to 5 and I can now create new EquipmentData and save/load it from my save files without having to add them to the reference manager. There's no noticeable slowdown yet, probably because my project isn't that big right now, but I will consider either re-organizing some of my code or learning more about editor scripting if the depth value happens to cause problems.

If you don't mind me asking one more thing, are there any specific things I should keep in mind when changing the CollectDependenciesDepth value?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Reference with ID could not be found - Nested Scriptable Objects

Post by Joel »

Glad that's working for you now.

The only other thing to consider is that if you update Easy Save this will be overwritten. Other than that, as long as it's not causing freezing in your project then it should be fine.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Tmoua96
Posts: 3
Joined: Tue Jan 17, 2023 7:02 am

Re: Reference with ID could not be found - Nested Scriptable Objects

Post by Tmoua96 »

Understood. Once again, thanks for the help and I'll keep those things in mind.
Post Reply