Question by
Harsiel · Apr 15, 2020 at 10:53 PM ·
c#scriptableobject
Attach a ScriptableObject Asset to a GameObject in code
I have several Assets of a ScriptableObject for my project, and am looking to assign them to a GameObject, the only solution I could find is as below:
public static DerivedStatWeight Get(string race)
{
var raceAsset = AssetDatabase.FindAssets(race + "DerivedStatWeight");
var guid = AssetDatabase.GUIDToAssetPath(raceAsset[0]);
var asset = AssetDatabase.LoadAssetAtPath<DerivedStatWeight>(guid);
return asset;
}
Surely this can't be the most efficient solution. Is there a better way to get the Asset in code?
Comment
Your answer
Follow this Question
Related Questions
Access an Array of class inside another Array of class? (EditorGUILayout) 1 Answer
Assign multiple Camera values to a single Scriptable Object 1 Answer
Assign ScriptableObject (Inventory DataBase) 0 Answers
Serialize a list of class containing ScriptableObject assets 0 Answers
SetDirty won't work on Nested List 1 Answer