Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

The name 'PrefabUtility' does not exist in the current context

Discussion in 'Scripting' started by Spraxs, Sep 16, 2018.

  1. Spraxs

    Spraxs

    Joined:
    Sep 16, 2018
    Posts:
    1
    Hello I am trying to make a copy of a prefab and then disconnect the copy from the prefab. This code works fine when I run my game in Unity, but when I am trying to build my game it gives me an error.



    This is my code:

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEditor;
    3. using UnityEngine;
    4.  
    5. public class UserModule : MonoBehaviour {
    6.  
    7.     private IDictionary<string, User> users = new Dictionary<string, User>();
    8.  
    9.     public GameObject userObject;
    10.  
    11.     void Start()
    12.     {
    13.  
    14.     }
    15.  
    16.     public User getUser(string id)
    17.     {
    18.         return users[id];
    19.     }
    20.  
    21.     public User createNewUser(string id, float x, float y)
    22.     {
    23.         Debug.Log("Creating new User..");
    24.         GameObject gameObject = Instantiate(userObject, new Vector3(x, y, 0f), Quaternion.identity);
    25.  
    26.         PrefabUtility.DisconnectPrefabInstance(gameObject);
    27.  
    28.         User user = gameObject.GetComponent<User>();
    29.  
    30.         user.setup(id);
    31.  
    32.         users.Add(id, user);
    33.  
    34.         return user;
    35.     }
    36.  
    37.  
    38.  
    39.     public void removeUser(User user)
    40.     {
    41.         user.remove();
    42.         users.Remove(user.getID());
    43.     }
    44. }
    45.  
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,050
    That's an Editor only function (Using UnityEditor), the script should reside in an Editor folder, and won't be available at run time.