Scriptable Objects Tutorial: Getting Started | Ray Wenderlich

In this tutorial you’ll learn how to create and use Scriptable Objects in Unity. Scriptable Objects in Unity can increase your workflow, reduce memory usage, and even decouple your code architecture.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/6183-scriptable-objects-tutorial-getting-started

Hi. can you make tutorials on IAP and Photon?

can’t find the Game Event Listener component.

@jayfeesh Can you please help with this when you get a chance? Thank you - much appreciated! :]

1 Like

Hi @frohmen sorry for the delayed response.

The Game Event and GameEventListener you create as part of the tutorial. They are two separate C# scripts
GameEvent.cs and GameEventListener.cs

Take a look under the section “Event-Based Scriptable Objects”. You should see a caption “Game Events and Listeners”.

Cheers!

Yes of course and I have added both of them.

Using Scriptable Objects to hold Item Data seems like the right way for me at the moment, but your solution is too complicated in my opinion.
Adding an event and eventlistener for each sword seems unnecessary to me, at least if you only want the information, which one was selected last. What are you gonna do if you have many more items?
I can think of 2 easier options right now:

  1. You create specific GameEvent and GameEventListener classes for the swordData type, where you either assign a field or property which the Listeners can get as soon as they are called. Or you pass the sword reference like an EventArgument to your event and from there to your listeners.
  2. Create a Scriptable Object, which just stores a reference to your last selected sword data item. This will be attached to every sword and the reference will be set set in your OnMouseDown bevore the Event.Raise(). Listeners will also have the refence object attached and look it up when called.
    With both methods you would only have 1 GameEvent and 1 Listener component per Listener object.

@jayfeesh Do you have any feedback about this? Thank you - much appreciated! :]

Hi @tobilaforge,

Thanks for your interest in the tutorial. I especially like your second suggestion that utilizes an additional Scriptable Object to keep track of the last sword selected. If there’s one thing truly awesome about programming, it’s having a hundred different ways to solve a problem. This being a tutorial, I really wanted to drive home creating Scriptable Objects, and utilizing Unity Events within a Scriptable Object.

Thanks for this, I was thinking the tutorial was not very scalable. I tried out option 2 and it is a lot nicer than having to create loads of event listeners and game events for 100’s of shop items.

Umm, this doesn’t work in unity 2019.1.8f…What do i do? a whole bunch of packagecache errors?

I just want to say that I love your tutorials. They are really well done and are super easy to follow. I wish there were more tutorial sites like yours. It really makes learning a new skill easy and fun.

1 Like

@jacheima Really glad you like them! Cheers! :]

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!