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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Is there an alternative to PrefabUtility for Android ?

Discussion in 'Scripting' started by subzer0, Apr 3, 2018.

  1. subzer0

    subzer0

    Joined:
    Dec 10, 2010
    Posts:
    94
    Hello,

    I am making a game for Android, and got an error when building, saying that "
    'UnityEditor' could not be found".

    The problem is that there is this piece of code that uses PrefabUtility and depends on UnityEditor :

    Code (CSharp):
    1. GameObject temp = Instantiate (myGameObject);
    2. GameObject prefab = PrefabUtility.CreatePrefab("Assets/Resources/Prefabs/MyPrefab.prefab", temp, ReplacePrefabOptions.ReplaceNameBased);
    I want to know if there is an alternative to PrefabUtility, or if I can change the code above and make it work on Android build ?

    Thanks.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Nothing outside of the editor could use that.

    Just out of curiosity, what would be different when you re-save this new prefab?
    (asking because if it's some details you could store/serialize to a file and reload/set, that could be an alternative).
     
  3. subzer0

    subzer0

    Joined:
    Dec 10, 2010
    Posts:
    94
    @methos5k
    I am making a logo guessing game, and each level has 25 logos.

    Sometimes the player may exit the game before finishing the level and guessing all the 25 logos.

    So that's why I wanted to save the list of logos in a prefab and then when he tries to play the same level, I load this prefab that contains the logos and he will continue from where he left instead of starting over from the first logo.
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Sure, well you could save a list of ints instead - either those guessed or unguessed, and reload the objects at those indexes, from your list, instead? :)