Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Compile error PrefabUtility

Discussion in 'Android' started by parasite7, Nov 19, 2013.

  1. parasite7

    parasite7

    Joined:
    Oct 21, 2013
    Posts:
    4
    Hello!
    I'm currently developing my android game, and some time, i need to use this code:

    Code (csharp):
    1. var prefab : Object = PrefabUtility.CreateEmptyPrefab("Assets/Scenes/Levels/MyLevels/"+name+".prefab");
    2.     var Map : GameObject = new GameObject();
    3.  
    4.     for(var a = 0; a < mapTileSaved.length; a++){
    5.         var go : GameObject = mapTileSaved[a] as GameObject;
    6.         go.transform.parent = Map.transform;
    7.     }
    8.    
    9.     PrefabUtility.ReplacePrefab(Map, prefab, ReplacePrefabOptions.ConnectToPrefab);
    so i use PrefabUtility to create a new prefab, but, when i go to build the project, it doesn't reconize PrefabUtility, and i can't compile, so, the question is, is there some way to use PrefabUtility on android, or i misunderstood this functions


    Thanks in advance
    o/

    **EDIT**
    Now i know, that since PrefabUtility is from UnityEditor, i can't use it on some built game, so, there's another question, is there a way to create a prefab at runtime (built game)?, because i create a map editor, that instantiate prefabs so you can drop they at certain position, and at the end, you can save them as a child of an empty root GameObject, that is later create as a prefab, and so, you can play your map simply by creating a instance of that prefab, if it's not possible to do that, can you guys give me some tips by create that kind of system?
    **
     
    Last edited: Nov 19, 2013
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    No, you can't modify or create prefabs at runtime. You need to use PlayerPrefs or another solution to store your data.
     
  3. parasite7

    parasite7

    Joined:
    Oct 21, 2013
    Posts:
    4
    yea :/, but save on PlayerPrefs I think is out of question, its something around 100+ gameobjects, and I need to store the position aswell
    so, if someone could give me some hints, on how can I store that game objects, i'll realy appreciate

    Thanks in advance
     
  4. shekalo

    shekalo

    Joined:
    Dec 21, 2017
    Posts:
    10
    I use #IF UNITYEDITOR and wrap it around the PrefabUtility script