- Home /
How to make game moddable?
I am making sandbox game and:
All items have ScriptableObject template
All player-world interactions are ScriptableObjects
I would like them not to be added to one resource file like unity does but I would like them to persist in separate folder after build for potential modder to edit and I also would like to do it so modders can add new items. I read about exporting SOs to Json files but I don't know how that would handle textures loading in case od modded items. How should I handle this SOs loading and persisting after build considering textures references? Documentation is not very helpful explaining AssetBundles etc.
Answer by andrew-lukasik · Apr 05, 2020 at 09:51 PM
Serialize your data to text files (json is probably just fine) and put them into Application.persistentDataPath folder. This, for example, is how you may go about reading texture files:
string mod = "Vanilla";
string subFolder = "Textures";
string fileName = "mod_me_if_you_dare.png";//make sure this file exists (project)/Assets/StreamingAssets/Vanilla/Textures/here
string path = System.IO.Path.Combine(
Application.persistentDataPath ,
mod , subFolder ,
fileName
);
byte[] bytes = System.IO.File.ReadAllBytes(path);
Texture2D texture = new Texture2D( 1 , 1 );
texture.LoadImage( bytes );
texture.Apply( true , true );
relatedMaterial = texture;
Building on this you can read fileName from that json you mentioned - where given asset would be described (or all of them).
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Custom assets give Missing (Mono Script) 0 Answers
Create List of custom class types, for use in custom editor 0 Answers