This meant that if I was on a team with a programmer and a game designer, for example, the programmer could create custom asset types, and then the designer could create instances of those types, for example, rooms, and populate them with descriptions, exits, and interactable items, all via editing in the Inspector. I also used them to create each item, possible action, and action response. In this case, I used ScriptableObjects to create custom data asset types for each ‘room’ in the game. This project provided a nice opportunity from a teaching perspective to present some ideas about architecture and patterns, including the use of ScriptableObjects, that I think would have been difficult in a more visual style of game. You don’t need a powerful 3D engine to make such a game, but I found it to be a very fun programming exercise and many folks who follow our content on YouTube seemed to enjoy it as well. Creating a Text Adventure game in Unity is, of course, massive overkill. I used them for this purpose to create a similar pluggable architecture, in my Text Adventure Live Training series. The Pluggable AI system is, I think, a nice example of the ‘modular code asset’ style of using ScriptableObjects, but importantly, ScriptableObjects can simply be used as custom data containers as well, to great effect. I hope to be able to do this someday in the future (maybe) ((no promises!)) :) Adding a nice Editor Window or Inspector to enable easier, more elegant editing and configuration would be a way to make it even more beautiful. I won’t claim to have improved on Richard’s work or idea, but I very much enjoyed creating the system and I have used it in some personal projects with results I am happy with. The result is my own Pluggable AI With Scriptable Objects Live Training Session. I wanted to also allow the configuration of those 'brains' and the creation of variants and styles of behavior using a similar ‘pluggable’ approach. Once I understood the pattern I thought it would be really interesting to create a variant of his idea. I thought this concept was really fascinating and dug into his public source code to see how he had put it together. One of the use cases that Richard demonstrates in this talk is a pluggable AI system with different ‘brains’ that can be plugged into AI tanks. For a ground-up primer on what they are, how they work and some example use cases, I highly recommend you check it out. I learned about ScriptableObjects and was inspired to begin using them by watching my colleague Richard Fine’s excellent Unite talk on the subject “Overthrowing the MonoBehaviour Tyranny In a Glorious Scriptable Object Revolution”. All of the pieces of code which compose the AI behavior are stored in ScriptableObject assets, which you can then configure and combine in the Inspector, without writing additional code. An example of this is seen in the video series below showing the Pluggable AI System. These values also persist after being changed in play mode, since we are changing a value on an asset.Īnother way that we can use them is to create assets which hold executable code. This can help with both the centralization of data and version control. You could simply edit a single value on our ScriptableObject asset, as opposed to having those values stored in the public fields of a MonoBehaviour attached to an enemy prefab or prefabs. Say you want to change the maximum speed of all those enemies. One example would be to create a custom asset that holds all the statistics for a given enemy type. So what are they? To quote the manual “A class you can derive from if you want to create objects that don't need to be attached to game objects.” This is a good start, I’d add to this that they allow you to create objects which are assets which can either hold custom data or execute code. They offer an interesting set of tools to extend your programming toolkit in Unity and helped me to think about certain architectural problems I’d been having in my projects a little differently. When I did learn about them, however, I got ScriptableObject fever. I would not call them something that beginners urgently need to know when getting started. I had been programming in Unity for a decent amount of time before I learned about ScriptableObjects. I've produced some online video training using ScriptableObjects and thought it would be cool to put them together in a blog post, along with a few related Unite talks by people much smarter than me, and so here we are! I make stuff in Unity and teach others how to do it via our Twitch channel and on YouTube. I'm Matt Schell, the Senior Screencaster on the Online Evangelism team at Unity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |