Copy a resource file to build directory?


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.


Why not use the StreamingAssets folder? That’s for those cases I think.

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.

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));