![]() ![]() This script will hold two copies of the same “Demo1Data” instance. Begin by creating a new script called “Demo1” and another called “Demo1Data”, also add an editor script called “Demo1Inspector”: ![]() Let’s begin with some serialization examples. Demo 1 Loss of object references on serialization The following two demos show how Scriptable Objects overcome those same issues. The first two demos show how you might run into problems if you weren’t using Scriptable Objects. I have created several mini demos for clarification on these points. The Serialization benefits are not equally applicable to runtime.You can’t create them using normal constructors, but must use “CreateInstance” instead.You must inherit from Scriptable Object, which may break many of your design or architectural options.They don’t need to be attached to Game Objects.They can handle polymorphism, whereas normal classes end up being treated as the base class.This can help you avoid data duplication. They save by reference, whereas normal classes and structs are serialized as full copies.They can survive an assembly reload (such as any time you build your scripts or enter and exit play mode).Of course you may be wondering “why” you would want to use a Scriptable Object. If you have been using tradtional C# classes or structs for simple data-only objects, you could optionally use these instead. You can think of a scriptable object as an object that is meant only for holding data. In this lesson we will cover what they are and how to use them. They have several important benefits but may not work ideally for every scenario. Scriptable Objects are a special type of data object in Unity. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |