1
\$\begingroup\$

I would like to copy a 3D model from external library and save it in temp/Resources/StreamingAssets folder to instantiate an object in unity scene. `

public class FBXOBJLoader : MonoBehaviour {

    string src;
    // Use this for initialization
    void Start () {
        src = EditorUtility.OpenFilePanel("Select Model", "", "fbx");
        //Output the Game data path to the console
        Debug.Log("Path : " + src);
        StartCoroutine("CopySomething");
    }

    IEnumerator CopySomething()
    {
        print("Start");
        string path;
        path = Application.temporaryCachePath;
        FileUtil.CopyFileOrDirectory(src,path);     
        yield return null;
    }
}

It's creating some unknown file format in the asset folder. can anybody please help me to complete this task.

Thanks in advance

\$\endgroup\$
  • \$\begingroup\$ Now it's storing in temp. does anybody know how to use it in unity scene? \$\endgroup\$ – Manoj Balaji M Nov 19 '18 at 9:56
1
\$\begingroup\$

The issue is that Application.temporaryCachePath returns the folder, you need the intended filepath. If you print it to the console it looks like this: C:/Users/MyName/AppData/Local/Temp/SomeCompanyName/SomeProjectName

Therefore, to fix the issue, change:

path = Application.temporaryCachePath;

To:

path = string.Concat(Application.temporaryCachePath, "/", Path.GetFileName(src));

Note, to use Path.GetFileName you must add using System.IO to the top of your script.

\$\endgroup\$
  • \$\begingroup\$ after that how can i instantiate an object into unity scene. consider my 3D model name is "flask". Now i selected the flask it not showing any error now can you please tell me how to use it \$\endgroup\$ – Manoj Balaji M Nov 19 '18 at 8:27
  • \$\begingroup\$ That is a whole other question in itself. I suggest you accept the answer for this specific question if it solved your issue and ask a separate question about instantiating an FBX at runtime. \$\endgroup\$ – mr-matt Nov 19 '18 at 8:33
  • \$\begingroup\$ it is a part of my question. Please check my title and content. i clearly asked - in title -> how to use it in game? - in message body -> temp/Resources/StreamingAssets folder to instantiate an object in unity scene. \$\endgroup\$ – Manoj Balaji M Nov 19 '18 at 8:44
  • \$\begingroup\$ If you insist, then I suggest you have a search on google first. There is plenty of help available. \$\endgroup\$ – mr-matt Nov 19 '18 at 8:46
  • \$\begingroup\$ Sorry mr-matt, I am requesting you. you are the person helping me here. i just want to show the 3d model from external folder to unity scene. for that i tried many ways but failed. now i am trying a new method to copy the selected 3d model to my application temp and try to use this. so only i raised this question. if my words hurt you i am really very very sorry for that. Hope i ll get help and Thanks \$\endgroup\$ – Manoj Balaji M Nov 19 '18 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.