Quantcast
Channel: Questions in topic: "class instance"
Viewing all articles
Browse latest Browse all 131

Null Reference Error With Scriptable Objects

$
0
0
Custom Scriptable Object public class GameDataScriptableObject: ScriptableObject,ICSVReader where T : class { public T[] mData; public T GetFromId(uint ID) { for (int i = 0; i < mData.Length; ++i) { var data = mData as IReturnID; if (data.GetID() == ID) return mData; } return default(T); } public GameDataScriptableObject() { } public GameDataScriptableObject(T obj) { } public void ParseCSV(string data) { var engine = new FileHelperEngine(); mData = engine.ReadString(data); } } Interface public interface ICSVReader { void ParseCSV(string data); } Helper Function public static UnityEngine.Object CreateAsset(string assetFileName) where T : ScriptableObject { var scriptableObject = ScriptableObject.CreateInstance(); TextAsset csvAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(TextAssetDataLocation + assetFileName + InputAssetFileExtension); if (scriptableObject == null) Debug.Log("NULL"); var parser = scriptableObject as ICSVReader; parser.ParseCSV(csvAsset.text); UnityEditor.AssetDatabase.CreateAsset(scriptableObject, AssetDataBaseLocation + assetFileName + AssetFileExtension); UnityEditor.AssetDatabase.SaveAssets(); return scriptableObject; } i have written a helper function to create an ScriptableObject from a csv file My problem is.... whenever i call CreateAsset>("EnemyData"); // EnemyData is the name of the text file and eachskill is a data structure i get an error !!!! here "parser.ParseCSV(csvAsset.text);" - > Debug Prints "NULL" which means ScriptableObject.CreateInstance failed... how ever if i have a class like this public class EnemyData : GameDataScriptableObject { } and if i call the same function again like this CreateAsset("EnemyData"); It Works Perfectly!!!!!! What am i doing wrong here? and why is the code behaving like this.? Any sort of help would be really helpful!

Viewing all articles
Browse latest Browse all 131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>