- Home /
How to get an object (asset) from his path ?
I know how to do to get the path of an asset, but I can't do the opposite.
Is it possible to get an Object from his path ? Does a function that would look like : Object obj=GetGameObjectFromPath(path) exists ? I want to do this in the game so without using AssetDatabase.
If it doesn't, is it possible to use DestroyImmediate with a path name ? Or any other destroy function ?
Thank you.
Answer by DiegoSLTS · May 27, 2015 at 02:32 AM
Look at this: http://docs.unity3d.com/ScriptReference/Resources.html
Basically, to load assets manually at runtime you have to place them in the Resources folder, you can't just load any asset in your project.
The problem is that the asset is a movie so in order to play correctly it must be in the "strea$$anonymous$$g assets" folder. Actually I don't want to load it but just to destroy the file after it played once to free some memory and GPU power. Is it possible to do so ? Thank you for your answer tho ;)
Once your movie is played, just make any reference to it as null:
$$anonymous$$ovieTexture my$$anonymous$$ovie = Get$$anonymous$$y$$anonymous$$ovie();
my$$anonymous$$ovie.Playe();
// When you are done with it:
Destroy(my$$anonymous$$ovie);
my$$anonymous$$ovie = null;
The compiler will do the rest.
You do not destroy the asset just the reference. The asset is in Strea$$anonymous$$g folder so it is in the RO$$anonymous$$, you want to free the RA$$anonymous$$.
Actually I'm on iOS and I use Handheld.PlayFullscreen$$anonymous$$ovie so I can't store the movie in a $$anonymous$$oviePlayer variable (not allowed on iOS). That's why I need to use the movie path in Strea$$anonymous$$g Assets. Can I use the Destroy() function with a path ? Or can I store an object in a variable from his path ?
Your answer
Follow this Question
Related Questions
Access path of stored asset 0 Answers
Why does Unity create folder/file only when I re-import the script that triggered it? 1 Answer
How do I move the Asset Folder to another drive? 0 Answers
How to tell if a texture was generated at runtime? 1 Answer
EditorUtility.OpenFilePanel uses \ FileInfo.Name uses / 0 Answers