- Home /
How to include a file into the game build?
My native plugin needs a large-ish binary data file, which it reads via C fopen/fread functions. Note the "large-ish" part, so storing it as a resource and then copying to the filesystem at runtime is undesirable.
Is there a way to have Unity include it into the build as a loose file?
Answer by DaveA · Nov 05, 2013 at 04:22 AM
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using System;
using System.IO;
using System.Collections.Generic;
public static class PostBuild
{
[PostProcessBuild]
static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
{
string path = Path.GetDirectoryName(pathToBuiltProject) + "/" + Path.GetFileNameWithoutExtension(pathToBuiltProject)+"_Data";
FileUtil.CopyFileOrDirectory ("Assets/somefolder", path+"/somefolder");
}
}
hi,
i know this is old post but i have an issue with the iOS build. Your code helped me copy the assets but i am not sure where am i supposed to copy the binary files so that the xcode actually packs them in the game and read the files. Like the TestiOS folder contains the whole xcode project and its related files and the game code is looking for Assets/Resources/FX folder to read the file. Xcode simply trows and exception as:
IsolatedStorageException: Could not find a part of the path "/Assets/Resources/FX/Filename".
Thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613121246im_/https://answers.unity.com/themes/thub/images/avi.jpg)