0

i have the next problem, I'm trying to make a prefab from a gameObject by doing this:

GameObject Res = GameObject.Find("Object");
UnityEditor.PrefabUtility.CreatePrefab("Assets/Temporary/Object.prefab", Res);

But it throws me this Error:

The name `UnityEditor' does not exist in the current context

What I'm trying to do is that when the user press a key it saves the object as prefab, so I can retreive it later in the game.

1 Answers1

3

Anything from the UnityEditor namespace cannot be used in a build. PrefabUtility.CreatePrefab is from the UnityEditor namespace and therefore can only be used in the Editor. This is why you are getting that error when you try to build your project.

As for saving your GameObjects, only save what you need to save. Importantly, get the components attached to the GameObject then serialize and save their values. You can serialize it to binary, xml or json. This will get you started if you want to save it as json.

Programmer
  • 121,791
  • 22
  • 236
  • 328