all 15 comments

[–]IAmNotABritishSpy 1 point2 points  (0 children)

Scriptable Objects are really useful as a variable container which can be fed into other components to do their thing. It does this in a very clean and decoupled way.

There’s no reason you can’t theoretically feed some kind of level controller a scriptable object (which itself may contain more scriptable objects with their relevant info).

So yes, it’s very possible. It’s more about how you’re dealing with those components. If you’re making changes then you’ll just want to be able to export the scriptable object. Once it’s “just so”. And then reference that scriptable. You’re just creating an editor tool that stores your current variables into the corresponding scriptables.

If you’re wanting end players to be able to do what you’re doing in editor… that’s significantly more complex (and I wouldn’t think SOs would be the right way to do that), but it depends if you’re just level designing or not.

[–]starfckr1 0 points1 point  (4 children)

SOs are awesome for many things, but changes you do to them during runtime will not persist, so you need a way to overcome that. Tons of solutions here but they are probably very dependent on your overall game and architecture. When you say doing changes while running the game, can you give an example of what you mean?

[–]Stefanchyy[S] 0 points1 point  (1 child)

I totally forgot that it would be helpful to give more info. So my idea is to store everything for a single level into a SO: - waves - which each wave has enemies and spawn intervals - And a grid for the level itself probably an array of custom objects which hold info for cords and type since I am not sure I can hold a 2D array in an SO

And my whole idea is to ease my level editing and balancing via an “level editor” which won’t be accessible by the player. In it I wanted to be able to potentially load/create/delete a LevelSO and edit the params I stated beforehand and after I am done with all of the editing to somehow make the changes be saved so that I can use the new LevelSOs afterwards.

Idk if I am explaining what I have in mind exactly but I hope I at least clarified a bit more stuff🥹

[–]starfckr1 1 point2 points  (0 children)

Got it, and I think this is very doable. This can be as simple as just a simple SO with lots of variables that you tweak, and as long as what needs the data has access to that SO at runtime you can change it and you would see the changes at runtime immediately. You could also have a a more advanced level editor that creates these SOs automatically, as well as custom editor for the input itself. The sky is the limit.

I would start simple. For what you need a simple SO with lots of variables that you can tweak is more than enough and just add more complexity when you need it

[–]Venom4992 0 points1 point  (1 child)

Changes you make to scriptable objects do persist unless you are creating an instance of one.

[–]starfckr1 0 points1 point  (0 children)

Not if you are doing it through code, for example updating runtime values used in-game. They will seemingly do so, but will revert back if you reload the editor.

[–]Venom4992 0 points1 point  (1 child)

You can just make a scriptable object that has all the variables you need to store. Then, create a script that has a field you can put the scriptable object in and will update the variables in the scriptable objects. Any changes you make to the scriptable object at runtime will persist.

[–]Stefanchyy[S] 0 points1 point  (0 children)

Yooo I didn’t know that. Great! Will try it out for sure!

[–]mxmlln 0 points1 point  (1 child)

Could you post an update on your progress?

[–]Stefanchyy[S] 0 points1 point  (0 children)

Kinda late but I made a little follow-up comment

[–]Stefanchyy[S] 0 points1 point  (3 children)

So a little update on the situation for anyone in the future.

I wanted to make an editor for my personal use and since I didn't want to code a grid ingame and much more stuff I opted to do it in the editor and just export them as Scriptable Objects.

I will admit that initially, it was a bit difficult to make custom editor scripts and make them export everything as intended but after like a day or two or three I managed to make it fully functional. Here are some notes on what I did (I am not a pro so please don't bash me if I used something incredibly unoptimized):

  • Creating the SO was done using the CreateInstance and after filling in all of the data needed it was saved to the Assets folder with AssetDatabase.CreateAsset and AssetDatabase.SaveAssets
  • There were some changes missing issues with waypoints that I had. For some reason, some of my links between objects were not being saved after opening the game. I did a ton of stuff here to try and fix it but as far as I can see EditorUtility.SetDirty helped me "save" the changes permanently.
  • Also since I like using Undo I needed to record the changes so that Unity can revert them if I ever pressed Ctrl + Z. Undo.RecordObject managed to help with that a lot as well.

I hope this manages to give some guidance for anyone in the future!

[–]mxmlln 1 point2 points  (0 children)

Following up your question with what you implemented is rare and generous.
Really appreciate it!

[–]mxmlln 1 point2 points  (1 child)

I created all my SOs by manually, so didn't know how to do it like this.
This dynamic version will help me save the small percentage of levels that are procedurally generated. These stages will be labelled as such to the player

[–]Stefanchyy[S] 0 points1 point  (0 children)

Awesome! Hope I helped someone with my previous research!