Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question What's the difference between Object.Instantiate() and GameObject.Instantiate() for Prefab?

Discussion in 'Scripting' started by Jeizn, May 15, 2024.

  1. Jeizn

    Jeizn

    Joined:
    Dec 12, 2023
    Posts:
    3
    The script does not extend
    MonoBehaviour 
    and cannot call
    Instantiate()
    directly.
    In VS2022, when I use
    GameObject.Instantiate()
    , it will prompt
    GameObject
    unnecessary code, but when I use
    Object.Instantiate()
    , it will not.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,420
    There is only one static method, UnityEngine.Object.Instantiate<T>()

    Because many things in Unity are derivative of UnityEngine.Object, it's "available" everywhere.

    Just qualify it with the class prefix to use it anywhere from the main thread.