Hey 
Im in a situation were I would like to load a custom file wich would be a prefab out of a folder and instantiate it in game, say I build the game and its in “C:/MyGame” And the executable is in “C:/MyGame/Game.exe” I want the game to be able to get a prefab out of a folder like “C:/MyGame/Custom/MyPrefab.prefab” and then instantiate it in game does anyone have any ideas on how to do this?
Please help thank you!

Store the objects in an asset bundle and use that.
1 Like
@GroZZleR i would but i want to allow the player to plop a .prefab file in the folder and edit a text file and it would be part of the game ive already got the whole text file and including into the game part but not the prefab part
There’s no way to create an actual prefab object outside of the Unity editor, that I know of. You’ll have to read the text file and dynamically assemble a GameObject from the file’s contents. Here’s a tutorial on how to read file content, if that’s what you’re hung up.
If they made a prefab then they’re using the Unity Editor to make it so just use AssetBundles instead. The Editor is stripped from Builds so you don’t get access to the raw importing tools the editor provides, hence there is no built in way to read the files like you want. That is what AssetBundles are for.
Its that, a full custom solution, or some parsed runtime importing via LUA / JSON.
1 Like
@GroZZleR @LaneFox thank you both for your input i have found a way of copying the prefab in my folder wich is
FileUtil.CopyFileOrDirectory( “sourcepath/YourFileOrFolder”, “destpath/YourFileOrFolder” ); howether now i am wondering how to instantiate the asset it is safe inside my asset folder should i copy it into my resource folder? but would this work with a build of the game?
That will not work in a build, for reasons we’ve pointed out. Use the solutions we’ve already pointed out.
You need to do something like this, assuming your description file looks something like:
Joe
100
Rifle1
string[] lines = File.ReadAllLines(@".\Mods\Soldier.txt");
GameObject go = new GameObject();
go.name = lines[0];
Health health = go.AddComponent<Health>();
health.current = lines[1];
Weapon weapon = go.AddComponent<Weapon>();
weapon.type = lines[2];
But obviously way more complex and involved. Mods are no simple feat.