- Home /
Copy a resource file to build directory?
Hi,
Part of my game includes a native plugin I use, that needs direct access to my model's FBX file (and another file). Both of the files are part of my unity project, and I reference them in my scripts (their locations are saved as strings in my objects etc).
This becomes problematic when building the game for a standalone build. I don't know how I can flag files to be copied to the output directory. While I can manage this myself when its two files, that number will grow by a lot until the final version of our game.
Is there any way to automate this process? (Ideally, I would like to be able to flag certain assets as 'binary runtime assets' or something similar, and have them exported to the build directory. Is there any way to do this? Workarounds are also very welcome.
Thanks!
Answer by Clem · Mar 31, 2011 at 01:40 PM
You could write a custom build script that copies the file(s) for you. Something like:
string[] scenes = {"Assets/myScene.unity"};
BuildPipeline.BuildPlayer(scenes , "Build/game.unity3d", BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);
File.Copy(sourceFile, Path.Combine("Build", sourceFileName));
That would work, but would not be modular, as I have to put everything in one script. I could write an entire system for a custom build script, perhaps.
the only problem is that BuildPlayer is a function only available in Unity Pro
Answer by castor · Jan 17, 2017 at 07:36 PM
Why not use the StreamingAssets folder? That's for those cases I think.
https://docs.unity3d.com/Manual/StreamingAssets.html https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html
Because the question was from 2010 and there was no Strea$$anonymous$$gAssets folder back then. It's a "more recent addition". Specifically the support for the Strea$$anonymous$$gAssets for windows and mac builds was added in version 3.5. Before that feature was an iOS only feature. Also Application.strea$$anonymous$$gAssetsPath
was also added in this version.
You got my upvote since of course Strea$$anonymous$$gAssets is now the way to go. However keep the posting time in $$anonymous$$d next time ^^. Unity as well as UnityAnswers exist for a long time now and Unity has evolved quite a bit. A lot things that weren't possible in the beginning / a year ago are now implemented.
Good point! The reason I replied is because I was looking for an answer to the exact problem and didn't realize how out of the date the thread was. I honestly feel the answer is still valid, in the sense that another developer just like me will very likely stumble into this answer without realizing how old it is. Also, is there a way to flag an answer as outdated?
Answer by Jason 15 · Feb 19, 2011 at 04:40 AM
The only way I've found so far is to put your file(s) in the root of the Plugins directory and append the '.dll' extension to them, even if they're not dlls. For example, if you have text.xml then name it text.xml.dll. I had to load an XML file in an external .dll plugin (so I couldn't use the Unity Resources or TextAsset class). This is the solution I used and it works fine, if a little hack-y.
I've tried this on a $$anonymous$$ac build, but after building I could not find it within the $$anonymous$$ac package.
how could you access the files after the build? because unity places the Plugins folder within a different folder (which name is based on the exe name on Windows - EXE_NA$$anonymous$$E + "_Data").
Your answer
Follow this Question
Related Questions
Developer Console doesn't show up when using BuildOptions.Developer 0 Answers
Cancel build in PostProcessScene? 0 Answers
Automate exclusion of specific Android plugin from build? 0 Answers
Distribute terrain in zones 3 Answers
Create custom warning dialog on build, if a script or gameobject exists in the scene 2 Answers