- Home /
[Best practice questions] Prefab with scriptable object that has the said prefab in it
Hi,
I have a list of scriptable object of "Item", which I named as ItemScriptableObject. These scriptable object each has public GameObject prefabObject; in it as a variable, and as the name suggests I drag and drop the related prefabs to the scriptable object.
The prefab has a monobehaviour component Item.cs with public ItemScriptableObject data; as a variable. So, when I edit some value in the ItemScriptableObject, that value is immediately reflected on the prefab's data such as damage, distance, knockback (bool), etc, which are other variables included in ItemScriptableObject.
But from what I'm seeing in the inspector, it's somewhat circular--or infinite--loop of referencing. Scriptable object references prefab asset which references scriptable object which references prefab asset which references scriptable object... and so on.
So, I worry if what I'm doing is the best practice of using prefab / scriptable object. Is my way of setting up scriptable object / prefab okay, or would this practice cause some sort of trouble in the long run? If latter's the case, how should I do it?
Answer by SirCrazyNugget · Jul 13, 2021 at 08:41 PM
Absolutely fine. Object A which references Object B which references Object A etc is not an issue. You'll find similar patterns in many language e.g. Parent/Child references to each other.
I'd rename what you're calling them though, I always try to refrain from calling any variable "Data", try ItemStats, make it as descriptive as possible.
Your answer
Follow this Question
Related Questions
Using Part of prefab as script parameter 1 Answer
Add a GameObject as a sub-asset of a ScriptableObject 1 Answer
is having a Prefab reference inside a a Scriptable Object legit? 0 Answers
Referencing prefabs in scriptable objects disconnect in builds 0 Answers
Optimal architecture for card effects, prefabs or scriptableobjects? 1 Answer