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

about load asset by code.

Discussion in 'Scripting' started by roger-wang, Dec 17, 2014.

  1. roger-wang

    roger-wang

    Joined:
    Jun 8, 2013
    Posts:
    11
    hello, everybody.

    i'm comfuse about the asset load API.

    i want generate *.prefab file when import the *.fbx file.
    • step 1: load *.fbx file
    • step 2: Create *.prefab file
    • step 3: load *.prefab file and Instantiate it.


    i try the code such below, but return null: [Windows]
    Code (CSharp):
    1.  
    2.               var prefab = AssetDatabase.LoadMainAssetAtPath("");
    3.                 Debug.Log(prefab);
    4.                 // This instantiates the prefab into the Hierarchy.
    5.                 var instance = (GameObject)PrefabUtility.InstantiatePrefab(prefab);
    6.  
     
  2. roger-wang

    roger-wang

    Joined:
    Jun 8, 2013
    Posts:
    11
    i try it, but fail again.

    so, I think this is bug of Unity 4.6 version.