- Home /
Is it possible to create / replace prefab in builded game?
Hey, so I am making a game, where you can build your own things, by than i mean, you can join things with hingeJoints and i foud a way to save it with script like that:
static function CreatePrefab() {
var objs = GameObject.Find("Core");
var go = objs;
var localPath : String = "Assets/Resources/" + go.name + ".prefab";
CreateNew(go, localPath);
}
static function CreateNew(obj : GameObject, localPath : String) {
var prefab : Object = PrefabUtility.CreateEmptyPrefab(localPath);
PrefabUtility.ReplacePrefab(obj, prefab, ReplacePrefabOptions.ConnectToPrefab);
}
And it works while i am In Unity... When I am trying to build I have errors: Unknown identifier: 'PrefabUtility'.
Unknown identifier: 'PrefabUtility'.
Unknown identifier: 'ReplacePrefabOptions'.
Is there any way of going arround this? if not, how do i save it then, like other games do?
Answer by zipa · Sep 09, 2013 at 08:19 PM
Hello, you can't use PrefabUtility, ReplacePrefabOptions or any other Editor class in the builded game. Besides Unity compiles resources in a single data file, so you can't add new prefab in the builded game. If you use Unity Pro you can take a look at AssetBundles for using external resources in your game (http://docs.unity3d.com/Documentation/Manual/AssetBundlesIntro.html).
So theres no way of doing such a thing with free version of Unity?
You can serialize parameters of new objects (such as position, rotation, scale, names of used components and their parameters) to some config file. When it is need, you create new objects and deserialize object's parameters from this config file. I like to use X$$anonymous$$L format for this goal.