Hello guys,
i´m new at Unity and i got a Problem.
I have a database with information and i want to Create Scriptable Objects at runtime. When i Export that project i got an error: " Unity Editor is not in the current context" to fix the Export i use #if UnityEditor. The export is an Webgl project and i want that the export is creating the Scriptable Object and create object´s in the scene.
Is there another way except Asset database to create Scriptable Objects and load Scriptable Objects from an folder??
@HueSamai I save my Data from my Database into the Scribtable objects to get the Information tomy Prefabs.
I try it before without the Scriptable Objects,but then he duplicate some information.
Can you not use a class that saves the information and then sends it to a prefab? For instance, instead of adding a new asset you just create a new variable, like ScriptableObjectName variableName = new ScriptableObjectName();
Of course you would have to replace the ScriptableObjectName with the class name of the scriptable object.
You could then add information to the variable to store.
Instead of creating the scriptable object and storing the values, then loading the values and assigning them to a prefab, can’t you just load the information and then set the values. On the script where you load the scriptable object data (I assume this is for the prefab), have a global public variable called X and Z. Then instead of saying creating a scriptable object, just assign the values. Here is an example.
//Declare variables
var X;
var Z;
...
// transform.LookAt(transform.parent);
StartCoroutine(GetImage());
transform.position += new Vector3(X, 0, Z);
Hopefully this helps. This is not intended to be copied just to give you an idea of what to do. Also I would like to point out, that you are using UnityEditor.AssetDatabase and PrefabUtility, as they were not intended to be used. That is why I removed the saving Prefab bit of the code. Why do you want to save the prefabs, so that I can help you find an alternative.
The information will be lost, if it is not a global variable. So if it is created in a function, it will be created everytime that function is run, making the information not carry over. But if it is a global variable than it will not.