Create Scriptable Objects with Unity

July 16, 2018
protect

Objective

The main objective of this blog post is to give you an idea about ScriptableObject in Unity.

 

What is Scriptable Object?

What is the difference between ScriptableObject and Monobehaviour class?

What are Pros and Cons of Scriptableobject?

How to use ScriptableObject?

Let’s undertstand all the questions by taking one ride of this blog about ScriptableObject

According to Unity API documentation,

"ScriptableObject is a class you can derive from if you want to create objects that don't need to be attached to game objects."

Confuesed..?

Don’t worry, if you didn’t get it. Here, I will Explain what it means.

As we know, with Unity, everything is an Object.

Types of Object

Monobehaviours are one of the Objects.

GameObjects: In your scene, you can move around with transform.

ScriptableObject is a kind of Object but, it can only Contain Data.

So, they don’t get involved in the actual game.

I hope you understood the definition of ScriptableObject.

Let's discuss Pros and Cons of ScriptableObject.

Prose of ScriptableObject:

  1. Built into Unity

    • They’re very well maintained by Unity.

    • You can interact with them very easily in Unity inspector.

  2. Can be saved as Assets

    • You can create it as a mini file inside your project.

    • You can update that and save that as per your game requirements.

  3. Can save during runtime

    • If you change something during runtime it will actually remember that.

  4. Internal Solution

    • When you are trying to get the data during run time of the game, you don’t worry about parsing external files which will come into play more.

  5. Large amounts of Data

    • You can save millions of integers inside of a ScriptableObject.

    • So, there’s a lot of space(no size limit function).

  6. Add to Structure as you go

    • As you’re building a scriptable object and create few instances of it and realize ,ohh I need a new setting for ‘moveSpeed’ or whatever additional variable you need you can add, it won’t disrupt your variable.

    • Deleting variable can have a little bit negative impact.

Cons of ScriptableObject:

  1. Requires an editor scripting

    • If you want to make assets out of scripting then you have to know a little bit about it.

  2. Can’t edit outside Unity

    • If you’re working strictly with Unity that’s not really a huge issue.

    • But if you have like team base solution, where you want to send files to someone and have them edit then it won’t work.

  3. Can’t save once deployed

JikGuard.com, a high-tech security service provider focusing on game protection and anti-cheat, is committed to helping game companies solve the problem of cheats and hacks, and providing deeply integrated encryption protection solutions for games.

Read More>>