I want to bring up something I have been struggling with about SO’s - but frankly its… nutty stuff so hang in there lmao. Let me go ahead and apologize right now for my usual wall-o-text that I’m about to drop on you guys
What if I want an editor script that can generate a world, and save some data about the world as ScriptableObjects? And what if that actually contained inside that SO, references to other SO’s to create a sort of hierarchy of SO references?
Perhaps the short version of this problem I am about to describe is, how do you save one scriptable object as an asset, with a reference to another not-yet-saved instance of another scriptable object? If you do that - and then save the not-yet-saved instance of an SO later, does the reference get updated to the asset rather than the instance created? In my testing so far I’ve had some trouble doing that.
Here is the long version:
Imagine your working on a road network for AI drivers, and you want to make perhaps 1000 waypoints around your map for the vehicles to drive around in. Now the way I work through this idea is like this:
1)first generate a gameobject based network of waypoints, with normal monobehaviors attached holding all the relevant data (this is wasteful but who cares it is an editorscript and the client won’t deal with this)
2)when the network has finished generating and connecting (meaning saving a reference to the next waypoints on a waypoint) then go and create scriptable object instances to represent that same data (without gameobjects/monobehaviours involved).
3)these SO instances are “Tiles” which contain references to every waypoint in a certain area, so to do that you might have the tile itself be a scriptable object, and the waypoints another scriptable object.
Here is where the problem is - if you had instances of all the “tiles” and “waypoints” of the world, then go to save the assets, where you might expect them to have the same references (the Tile knows its Waypoints, the Waypoints know the next waypoints connected to it) - it doesn’t seem to work properly. Of course I may just be doing things wrong!
But it seems that some sort of ScriptableObject-ception happens, where you need to assign an asset that doesn’t yet exist to the “tile” scriptable object (the scriptable object instance for its waypoints perhaps hasn’t actually been saved to a file yet) so you end up with “type mismatch” in place of some of the variables in the “tile” or the “waypoint” ref to its next waypoints. Is it just an issue of bad coding practice by trying to mix/match the instances and the actual assets?
How do you deal with that? I can only imagine one way (which I’ll be testing after slamming on some food, happy turkey day ya’ll), which I suppose would be to create all the assets ahead of time rather than just instances, you know just loop to generate and save all those “instances” as assets, and then assign all the appropriate values to the asset itself somehow (I haven’t yet tried do this, but I hope its possible) so that the references are already set to the EXISTING scriptable object asset? Does that even make sense? Does any of this make sense? Haha… no seriously is what I’m trying to do a huge nonsense way of going about it? I ultimately just want to get away from monobehaviours and gameobjects to represent waypoints and the tiles they are in, because it would be lighter on the built game if I didn’t have an extra set of gameobjects/scripts sitting around basically holding data… and that is why I expected SO’s to solve this. While I have worked with them for way more simple tasks, I never tried this sort of referencing between them, so if anybody can suggest the proper way to do that, it would be fantastic! Or if you can let me know what would make more sense in this type of situation, where you wouldn’t need to do that at all… I’d like to hear that too!
As I understand it, just using “EditorUtility.SetDirty(someSOAsset);” and “AssetDatabase.SaveAssets();” should update the changes to the existing saved asset for the SO… is that correct? If not, how do you go about that?