No video

LIVE: Let's talk about Scriptable Objects - Should you use them?

  Рет қаралды 16,927

Jason Weimann

Jason Weimann

Күн бұрын

Пікірлер: 44
@coryronald6762
@coryronald6762 3 жыл бұрын
00:00:00 Preamble/Text From The Boss 00:01:00 Explanation of Scriptable Objects 00:02:00 Make a New Scriptable Object 00:06:00 Example 1: Recipe (Simplest) 00:08:00 Recipe Script 00:08:30 Example 2: Shared Data Across Scenes (Instead of Static Classes) 00:09:00 Shared Number Script 00:10:30 Example Project 00:13:30 Data saves after returning to inspector 00:14:00 Updating SharedNumber Script to use Inheritance correctly 00:16:00 Check out Unity Documentation on Scriptable Objects 00:17:00 Data Binding 00:17:00 SavedNumberBinding Script 00:18:00 Chat Check 00:19:00 Example 3: NPC Scriptable Object 00:20:00 Scriptable Objects vs Prefabs 00:21:00 Drawback: Scriptable Objects Don't Show Conveniently in the inspector 00:21:00 Update Background Image (lol) 00:22:00 Advice: If you have a complex data system, use a custom inspector to organize your info 00:24:00 Custom Inspector Example: Quest Inspector 00:25:00 Custom inspector vs Original (Make What layout works for you?) 00:26:00 Custom Inspector Explanation 00:27:00 Issue: Serialization of Scriptable Objects means saving off state is not so easy. Can't use inheritance with scriptable objects 00:29:30 Scriptable Objects Article (Check out Game Events and Listeners section) 00:30:00 GameEvents Scriptable Object 00:33:00 GameEventListener Scriptable Object 00:33:00 Set Up GameEventListener 00:39:00 Override game Event Covered In Next SO Video 00:40:00 Jump Into Chat 00:40:30 Q: Difference between Events and Unity Events? 00:40:30 Unity Event-> Connects Game Objects in inspector 00:40:30 Event -> Connects through code (Lower Level Details) 00:42:00 Save Data with Scriptable Objects-> JSON Objects 00:43:30 Smash That Like Button 00:44:00 Q: Interview Advice A: Research the Company/Interviewer beforehand 00:45:00 Q: Automated tests for scriptable objects? A: More like testing how those systems react with the Scriptable Objects 00:45:30 Q: Scriptable Objects vs Scene Persistence? 00:47:00 Wrap Up. Time For Science! 00:48:00 Like and Subscribe, share and Enjoy 00:48:33 Thanks Jason!
@PeachPuppy
@PeachPuppy 3 жыл бұрын
Good job man, thanks for splitting it up for when I’ll refer back to this!
@aurelienlerochbermuda6600
@aurelienlerochbermuda6600 3 жыл бұрын
Thanks
@coryronald6762
@coryronald6762 3 жыл бұрын
@@abo1428check out his video on saving and loading when he talks about collecting the money
@Spectralle
@Spectralle 3 жыл бұрын
Very helpful info, thanks! I recently made a modular scriptable-object-based system for projectile weapons where, among other things, the trajectory data for how the projectile moved was it's own SO and could be switched and applied to any other projectile weapon with any other parameters. It allows players to easily customize their weapons too.
@DePistolero
@DePistolero 3 жыл бұрын
hey, thanks, some time ago you wanted to copy reference scriptable object types from GDC so you can switch in inspector from value to reference type... I extended on that idea, started using scriptable objects events, and basically structured the entire project based on scriptables, everything really( saving data, scripts communication, values sharing, events ) made my project pivoting, scalability and modularity really fast and painless.
@shadmansudipto7287
@shadmansudipto7287 3 жыл бұрын
It was a unite talk, not GDC :D
@abdullah4653
@abdullah4653 Ай бұрын
awesome tutorial once again sir
@rahulcorleone4222
@rahulcorleone4222 3 жыл бұрын
Hi jason, thanks for sharing your knowledge with us. I wrote a scene arranging system with scriptable object and a custom editor with reorderable list to easily reordering build scenes(we have around 100 scenes for a hyper casual game) an creating different setups for release build and i made it independent from loading scene with scene build index, I had happy result with different setups for our build and a button to apply each scriptable object data to unity build settings. Another usage for scriptable object, maybe referencing components between game objects(or prefabs) in the project.that does not sound a bad idea, but maybe it would be better to develop some debug tools. because wiring alot of things inside unity editor, can lead us to headache when a bug happens :)
@Magnenator
@Magnenator 3 жыл бұрын
Good stuff as ususal, Jason. Long time lurker, first time commenter here Just wanted to add, Unity somewhat recently added the ability to do polymorphic serialization using the "SerializeReference" attribute. For SerializedProperty objects, then, you can access the data via their "managedReference" fields. As an example, you can have an array of some interface type on your ScriptableObject marked with [SerializeRefernce], and correctly save a mix of any elements that implement that interface. There are some caveats with this approach, but the docs do a pretty good job summarizing: docs.unity3d.com/ScriptReference/SerializeReference.html
@MaharbaRacsoChannel
@MaharbaRacsoChannel 3 жыл бұрын
I love them. They are quite buggy though. For example, they don't work well with prefab overrides. They also get recreated with some editor interactions. There are many other smaller, but annoying surprises, so I'd recommend to use them with caution.
@wtf_is_going_off
@wtf_is_going_off 3 жыл бұрын
Jason, content what you are doing is super cool and is very useful. Tonns of respect and million pluses to your karma :) One thing I would like to ask, is it possible to share the audoi version of your streams as a podcast format on Google podcasts or on Spotify. KZfaq isn't a suitable place for that. It pauses the video if I switch an app to run in background or turn off the screen.
@MaharbaRacsoChannel
@MaharbaRacsoChannel 3 жыл бұрын
I've found that if I open a youtube page in a mobile browser, but put the tab in desktop mode, the audio keeps playing.
@nguyenhaiang6198
@nguyenhaiang6198 3 жыл бұрын
Love your contents. I used scriptable object for UI quite a lot. This is very helpful. You should make a video about photon and playfab for multiplayer game, I'd like to here your opinion as well as some tutorials
@Paul-to1nb
@Paul-to1nb 3 жыл бұрын
My biggest wish has been wanting to serialize subclasses/interfaces and choose the type in the inspector (like the KillObjective you typed and erased). How do you get around that? I would love the polymorphism and encapsulation of type this would enable.
@MaharbaRacsoChannel
@MaharbaRacsoChannel 3 жыл бұрын
You can use the SerializeReference attribute (docs.unity3d.com/ScriptReference/SerializeReference.html). I've found them very useful in combination with ScriptableObjects. Be careful, because it currently has some important bugs, though. The two most important issues I know are: -They get easily corrupted in prefab overrides, so I'd avoid them in scripts used with prefabs, specially if you're using them for nested or graph-like structures. -They get recreated when doing ctrlz/ctrly. So avoid having any non-serialized fields in them; they can get easily lost. Also don't keep non-serialized references to them.
@yudnai5577
@yudnai5577 Жыл бұрын
how do you adress the issue of scriptble object can not persist in a real build between scenes?
@mnnm1989
@mnnm1989 Жыл бұрын
I think they are persistent in the build between scenes.
@mridulagrawal3435
@mridulagrawal3435 3 жыл бұрын
You are the best.
@Stopa42
@Stopa42 3 жыл бұрын
Helpful video, thanks. That bit about SharedNumbers and SavedNumbers cleared some stuff for me and the custom editor for a scriptable object looks neat! I was wondering if ScriptableObject would be a good alternative to MonoBehaviour for some event-based managers which do not need an update loop. For example in a multiplayer game you could have a PlayerManager that knows about all connected players, knows who is the leader of the group and can promote other players to leader. It changes only when a player is connected/disconnected or something in the party changed. Is SO a good option or is there a better way?
@zekiozdemir420
@zekiozdemir420 2 жыл бұрын
learned a lot thank you!
@JoachimVesely
@JoachimVesely 3 жыл бұрын
Why do you use Changed?.Invoke(); instead of just Changed?(); Is there a difference, or is it just a preference? I assume the optional ? will not invoke unless there is a subscriber?
@goldwhite1414
@goldwhite1414 2 жыл бұрын
Hey Jason, thanks for the great tutorials. If you see this message I was wondering how at 11:10 you were able to call the functions inside a scriptable object from the button OnClick() event. When I can assign a reference to the scriptable object inside the OnClick, but it doesn't show any of my public functions in that scriptable object... Thanks for ur time and stay awesome!
@nunodelgado20
@nunodelgado20 3 жыл бұрын
I have been using ScriptableObjects to create an ability system for mmo games like World of Warcraft and they seem extremely handy. I can esealy create an ability and change the mechanics and the use, cast and effect type without breaking the game. But of course, I am not very experienced in creating games and, thus, I don't know which type of issues I may encounter on a complete game. But from what I understood it can actually be very handy to save cooldown state of each ability between scenes by using coroutines. Or am I wrong?
@ilikechaandiwantsya.7832
@ilikechaandiwantsya.7832 3 жыл бұрын
You had player health but what if there is more than one player unit that had their own health stats. Would you need to create multiple player health scriptableobjects?
@coryronald6762
@coryronald6762 3 жыл бұрын
Depending on what kind of game, you could set up your characters to read "PlayerStartHealth" from the Scriptable Object. OR you could have "Player1Health", "Player2Health" etc The first one could be like units in Starcraft, (Where the number of units using the health would be variable) and the second would be like a Multiplayer FPS, or something like that, where there is a fixed number of total players. But there's no fixed rules, all depends on how you want to set up and organize your game.
@DePistolero
@DePistolero 3 жыл бұрын
I did that, created multiple health stats as scriptables and just assign them to needed objects during runtime, and worked like charm, Had events inside those scriptables that notify when the value had changed, really useful stuff.
@victoraurelius5334
@victoraurelius5334 3 жыл бұрын
to answer your question, yes you need to create multiple scriptable objects for each player, IF you read from that SO as a reference during gameplay (e.g. your UI updating health bar according to its value). If you only use it once as a starting value, and your UI script for example then has a private copy of that value in its own script which it works with, then one single SO for health would work for all players.
@abo1428
@abo1428 3 жыл бұрын
Hi Jason, great video as always. You said in the video that for larger environments you would choose a more reliable method. What would that be? Thanks!
@victoraurelius5334
@victoraurelius5334 3 жыл бұрын
I'm interested to know what Jason thinks as well. But here is my opinion. I tried to use the Scriptable Object Architecture (famous Ryan Hipple talk on KZfaq) in my rather complex project and quickly found out that you lose all references with this system. Specifically one example: you create a SO for "health". Then you have one script "Player" which you dock this SO to and "Player" writes damage onto it when received. Your "HealthBar" script also docks onto this SO and reads and updates the UI accordingly. This is all good and easily to remember. But in a more complex project, you may have a SO variable which is read/written to by 5, 10 scripts and you may have 50-100 SO's, or even more, for all kind of things. At this stage, you don't have any clue anymore which script is exactly listening, or writing to which SO. Because your IDE (Visual Studio) is unable to show you "referenced by", as you get with classes and methods. So you end up at a stage, where you don't even know if a specific SO is used anymore and safe to delete or not. It gets complicated really fast. It works for very small projects (like a flappy bird, or tetris clone), but anything larger - stay away of it. Instead, "the solution" would be to do everything in your classes and methods. Edit your starting values in exposed editor fields. If you are worried about cross-scene references, look up "additive scene loading", make a "Core scene" with all your managers and load/unload your gameplay scenes on top of it. And finally, use Scriptable Objects only for static mass data - like Items, Recipes, Quests, Dialogue, etc. But not for Events, Floats, Transform references, etc... which change during gameplay.
@MaharbaRacsoChannel
@MaharbaRacsoChannel 3 жыл бұрын
@@victoraurelius5334 I think he was talking about a more reliable method of saving in game data; but I could be wrong. On SO debuggability: There's an option in the asset's context menu to show all the objects that reference an asset. Also, you can always make custom editors to clarify and categorize references to an object. For example, you could show all the listener and triggers of an event object, and also a button to trigger the event from the inspector. Ryan Hipple says in his talk that their real implementations are more solid and have these kinds of editor tools. I've found that these approaches can actually be easier to debug with the proper tooling.
@Jobzachariah
@Jobzachariah 3 жыл бұрын
Hey Jason , Love your videos , Can u please make a video of how to create a blackboard for AI coding and understanding core concept of Blackboard ,Decorators etc
@kambaalayashwanth123
@kambaalayashwanth123 3 жыл бұрын
Hey JSON , can you please provide info about font and theme of the editor at 3:41 , is it a default one . Thank you
@seppukun208
@seppukun208 3 жыл бұрын
Hmmm I thought scriptable objects always saved in editor and cannot save during a build after restarting the app...
@mattjclay
@mattjclay 3 жыл бұрын
The answer is yes
@CoffeeAI201
@CoffeeAI201 3 жыл бұрын
You look like Mark Hamill. Thanks for sharing this content!
@restushlogic5794
@restushlogic5794 3 жыл бұрын
Please make tutorial async await for UniTask.
@brianjensen2532
@brianjensen2532 3 жыл бұрын
Yes :)
@DePistolero
@DePistolero 3 жыл бұрын
Absolutely!!!
@Dippps
@Dippps 3 жыл бұрын
Hello. I saw you use events in scriptable obj. I think it make things too complex when you have several events and you actually have to check everytime that you set up correct event in inspector. I use static events in projects now. They are easy debuging.
@anishsrivatsan2332
@anishsrivatsan2332 3 жыл бұрын
Hi, Can u please make a tutorial on how to spawn random prefabs containing images in unity? Thanks a lot!
@kartikmanmode9974
@kartikmanmode9974 3 жыл бұрын
Make a top down shooter game
@mintydog06
@mintydog06 2 жыл бұрын
I found this video hard to follow. You were a bit all over the place, and I didn't see you make and set up an easy to follow scriptable object from scratch.
@carstenklein4568
@carstenklein4568 3 жыл бұрын
what about replaying some cool internet pr0n vids on the secondary display, would make this much more interesting... :/
The Ultimate Introduction to Scriptable Objects in Unity
20:45
WILL IT BURST?
00:31
Natan por Aí
Рет қаралды 27 МЛН
The Power of Scriptable Objects as Middle-Men
17:41
samyam
Рет қаралды 123 М.
EA Won't Let Me Play This Game - So I Hacked It
8:49
Nathan Baggs
Рет қаралды 311 М.
Be CAREFUL with Scriptable Objects!
8:27
Code Monkey
Рет қаралды 79 М.
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 179 М.
Unity 2021 Use Scriptable Object instead of Enum
10:57
Sunny Valley Studio
Рет қаралды 37 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 706 М.
The Most Legendary Programmers Of All Time
11:49
Aaron Jack
Рет қаралды 552 М.
Resetting Scriptable Objects - Unity Playmode
5:56
One Wheel Studio
Рет қаралды 2,3 М.
WILL IT BURST?
00:31
Natan por Aí
Рет қаралды 27 МЛН