Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    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. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

Discussion in 'Scripting' started by Spraxs, Sep 16, 2018 at 10:27 PM.

  1. Spraxs

    Spraxs

    Joined:
    Sunday
    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:
    869
    That's an Editor only function (Using UnityEditor), the script should reside in an Editor folder, and won't be available at run time.