- Home /
Loading a ScriptableObject at Runtime.
I have a few ScriptableObjects that act as configuration files for various things, like physics layers for example. It lets me keep track of which layers represent physical objects, characters, camera-blockers, etc.
Previously I was using AssetDatabase functions to load the Physics Settings.asset, but now that I have to build it I need to use something else. I'm assuming it's Resources.Load or something, but I can't figure out exactly what the function is supposed to look like. Basically I want to do this, but the configuration file I've created never loads up:
public static PhysicsSettings GetPhysicsSettingsAt (string path, string name) {
string fullPath = path + "/" + name;
PhysicsSettings file = Resources.Load (fullPath, typeof (PhysicsSettings)) as PhysicsSettings;
Debug.Log (fullPath);
if (!file) {
file = ScriptableObject.CreateInstance<PhysicsSettings> () as PhysicsSettings;
file.name = name;
}
return file;
}
Answer by David_Munoz · Nov 06, 2015 at 01:45 PM
You should Serialize the classes, an then save them as Assets, then you can save an load configurations as you wish (assuming all you have are ScriptableObject classes with public elements). Can you be more especific on what you have in your objects?
Your answer
Follow this Question
Related Questions
Store the path with Resources.Load in a string 3 Answers
Loading resources into a ScriptableObject instead of Resources.Load? 1 Answer
Problem with path in FileStream 2 Answers
Baffling Resources.Load by playerprefs string problem. 1 Answer
Unity not allowing drag and drop for assets in Project View 2 Answers