- Home /
Scriptable Object containing Scriptable Object
In my card game I have the following layout:
I create the asset in unity editor however when running
ArgumentNullException: Value cannot be null.
Parameter name: collection`
When checking in debug w/ visual studio it shows cards as being null:
How do I reference a scriptable object from another scriptable object?
The actual code comprises of decks, wich holds card stacks, which holds cards. Please note that card can have a reference to another card. When initialised a CardStack Derived class is instantiated it takes the cards entered by the design team in the editor and puts it into a new private list (A singleTypeCardStack contains one type of card but puts multiple copies into the deck) that is returned when CardStack.GetCards(); is called. A blockerStack is used to create sections within the full deck/deck class that it can then decide to shuffle or not without shuffling the whole deck. When Deck is instantiated GetCards() on all the card stacks and added to its internal list that returned when Deck.GetCards() is called. The class diagram is basically this:
I can upload the code if needed but some variables names are slightly different to those in the class diagram.
Hi. Are your cards also assets? If not, are you adding them as subassets to your decks with AssetDatabase.AddObjectToAsset? I'm almost sure of what it is, but, to be certain, can you open a problem Deck asset with a text editor and show us what it says?
Answer by ATLGAN · Mar 02, 2020 at 06:07 AM
You can do this using Editor code:
#if UNITY_EDITOR
public ExampleData FindAsset() {
string[] guids = UnityEditor.AssetDatabase.FindAssets("t:ExampleData");
if (guids.Length == 0)
{
ExampleData createdData = ScriptableObject.CreateInstance<ExampleData>();
return createdData
}
else
{
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[0]);
return UnityEditor.AssetDatabase.LoadAssetAtPath<ExampleData>(path);
}
}
#endif
What file do i put this:
Is it in every scriptable object, just one (If so is it the base card or the SO that references card?) or does it go in its own file?
Actually, it doesn't matter, because the method already return the data back, but I recommend you keep it in the script where you keep the data.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
An OS design issue: File types associated with their appropriate programs 1 Answer
Calling a derived class (Serialized in a Scriptable Object) returns the super class. 1 Answer
How can I improve the organization and storing of information for my FPS Character Controller? 0 Answers
Is it possible to make sealed overridden MonoBehaviour method. 0 Answers