AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Unity list of scriptable objects12/17/2023 ![]() We also want to be able to create the GameEvent from the To create our ScriptableObject Event we want to have our Class, named GameEvent, inherit from ScriptableObjects instead of MonoBehavior. We can use that same abstraction for Events. This saves you time when you eventually want to tweak values that would traditionally be stored in multiple places throughout multiple Classes or components. This is useful because you can centralize data that a lot of components will reference. A ScriptableObject can be used as an asset to hold data. If you do not know what a ScriptableObject is I would recommend you watch the two Unite talks linked above, but here are the basics. The first thing we want to do is create a ScriptableObject to hold our Event. Getting Started Create a ScriptableObject Event in Unity To do this we are going to create our ScriptableObject Event, write a custom UnityEvent, code a GameEventListener, and attach a response with a dynamic string. Today, we are going to show you how to solve this problem and pass parameters with ScriptableObject Events. ![]() This, however, couples your classes and makes them dependent on one another, which is bad for everyone. Then call a public method or set a public variable on that component. Usually, you would store or get a reference to the component you want to pass the new data to. ![]() Sometimes, you need to pass information with the Event to make it more useful. Sometimes, you may want to do a little more with your events besides just trigger another method or basic action. You can learn more about Events as ScriptableObjects from the great Unite talks given by Richard Fine in 2016 and Ryan Hipple in 2017. ScriptableObjects allow you to turn events and event listeners into modular pieces that you can plug and play across your GameObjects. The code just says “Hey, check this out!” and anyone that received the message does what they were told to do when they received the alert. The script or Class does not know or care about anyone on the list. When the event is triggered a message is sent out to everyone that has subscribed to the event’s mailing list. ![]() They allow you to decouple scripts and Classes from one another. How to Pass Parameters with ScriptableObject Events IntroductionĮvents are an essential component in having clean, understandable, modular, and encapsulated code. ![]()
0 Comments
Read More
Leave a Reply. |