I was just facing this problem. I tried some custom serialization, to find that it gives me trouble when switching to the HTML5 platform. I am not really savvy on serialization and its shenanigans, so I needed to implement a different solution.
In the end, my solution is a variation on the hack @Blub described:
-
Using platform-dependent compilation, I declare a serialized key-value struct for the dictionary I want to fill, and an array of this struct. This struct, array, and the function to use them, will only exist for the editor.
-
Create a scriptable object to contain the dictionary. This object I will be using in the game.
-
Run an editor function that stores the data from the array into the dictionary in the scriptableObject. Since it is an asset, you will need to use the AssetDatabase class to 1) set it dirty before modifying it; 2) save the AssetDatabase, 3) reload the assetDatabase.
The result is a visible list of items available in the editor, a plain old dictionary that will leave no extra trash and require no extra processing in the application, and an editor function that saves the first into the second.
Of couse, as some have mentioned, nothing stops you from putting duplicated key values into the array, so you need to be careful, or have the “Dumping” function check for errors like this. Other than that, I think it is a good compromise. This process of using editor-only variables and functions to process and store data into scriptableObjects has been pretty reliable to me, and I have been using it quite frequently with no problems.
What does PITA mean?
– ScifiSorry. Pain in the...butt.
– AutoplastyI'd suggest building the dictionary using the ISerializationCallbackReceiver interface, not on Start.
– Warrantor