![]() ![]() At its highest form it’s an incredibly lightweight and diverse design tool with which to simplify and communicate between different parts of your Unity project. It can be thought of as an interactive spreadsheet with which to organize, adjust, and categorize different aspects of a database. It’s a lovely standard by which to organize any information database. To sell it quickly, the Scriptable Object is an intelligent data container in Unity. One such tool in the quest for modularization is the Scriptable Object. Simply put, a good complex system should be made up of small, adjustable pieces that can interact with while remaining independent from one another. It is a mechanism for complexity redistribution.”¹ Modularity is “the degree to which a system is made up of relatively independent but interacting elements, with each module typically carrying an isolated set of functionality. Complexity cannot be avoided, but it can and should be handcuffed to its sober sponsor, Modularity. ![]() You will find that the deeper you delve, the higher the likelihood that one small tweak can corrupt your entire structure. ![]() The scenario gets even more complicated if additional classes such as enemy AI need to access the player’s health, but we’ll consider only the UI class for now.Reduce memory usage, organize, and make your project easily designable with Scriptable Objects!Īs grows the size of any system, so grows the complexity, and so the accompanying inconvenience of additions or adjustments made to it. Since the PlayerUI class directly depends on Player, those classes are closely coupled. The ‘traditional’ way to do this is to reference the Player directly via a variable on the PlayerUI script and read the variable directly. Other portions of the code, such as the UI, need to read that health value in order to display the health value. In my game, I have a Player class with an integer member variable to represent the player’s health. The designer must find the correct object instance in the hierarchy or prefab in the project view and modify values, which can be cumbersome. While it’s possible to expose variables to designers inside the Inspector through use of regular MonoBehaviour components, it can be clunky because you must attach them to a GameObject which needs to be instantiated in the scene either in-editor, cluttering up the hierarchy, or at runtime, which requires extra code to instantiate the object. On top of that, the Unity Editor’s interface is geared towards designers. In order to make code easy to change, as is especially common in game development, it’s a good idea to keep classes as loosely coupled as possible. Two portions of code are called decoupled when a small modification to one requires no or very minimal changes to the other. Let’s look at a few ways we can use this powerful tool to overhaul our projects.Ī good measure of how easy it is to change a piece of code without far-reaching ill effects is if there are few other parts of code that rely on it. The result will be a new object in the Project view in whichever folder is active. You can tweak the location of the option using the menuName and order variables, and the default name of the resulting asset file using the fileName variable. The menu is available by right-clicking in the Project view or using the Assets->Create menu on the toolbar. Creating a new type that derives from ScriptableObject works the same way as for any C# class – colloquially, when we inherit this class, we will say that we’re “creating our own types of scriptable object”. Unity assets are anything found inside the Project pane – audio clips and scripts fall under this category too. The primary usage for scriptable objects is to store data inside a Unity asset as an alternative to reading data from a file at runtime or containing the data inside a component attached to a GameObject. This article was available to $5+ Patreon supporters two weeks early. Let’s explore this powerful class and its features. However, there is another core class built into Unity which inherits directly from UnityEngine.Object but does not need to be attached to a GameObject to function: ScriptableObject. ![]() It derives ultimately from UnityEngine.Object through a couple of other classes and represents an object which must be attached to a GameObject to function properly – they are user-created Components. The MonoBehaviour class is probably the class you most commonly inherit from in Unity. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |