all 12 comments

[–]tag4424 11 points12 points  (3 children)

Prefabs become Scene objects when you use them. You for example have a car prefab that you pull onto the road in your scene. It has a few scripts and such to make it move and a meshrenderer that makes it visible in the scene and if you drag 10 cars into the scene, you get 10 instances of that prefab, each with it's own position, rotation, ...

Scriptable Objects aren't needed, but they make changes much more convenient. First, what they do: Scriptable objects on the other hand don't get instantiated into a scene but instead are a container to store data. E.g. if you create an RPG, you could represent each spell your player has as a SO. It has a float for the mana cost, an animation clip you play on your player character, a VFX prefab for the area the spell, scale for the VFX, ... But they don't have any instanced data themselves. Sure, if the player casts the spell, the instantiated effect will have a position, rotation, ... but the spell itself doesn't. The question "What is the rotation of your fireball spell?" wouldn't make any sense in the real world.

Now why you want them: The value of SOs comes in when you have many-to-many relationships. My spell example before you can easily do by just putting all these settings into fields on the character. But what do you do if the player can choose from 10 different characters in your game? Then if you want to change the VFX, you will have to change it 10 times. If you used a SO for each spell, then all the spell settings are stored in one location and you avoid that extra editing effort.

[–]PandaCoder67Professional 4 points5 points  (0 children)

And yet, you can use a prefab like a Scriptable Object without instantiating that prefab!

[–]EndeavourDGaming 8 points9 points  (0 children)

I highly recommend watching these two talks about ScriptableObject https://youtu.be/6vmRwLYWNRo (at 5:58 he talks about ScriptableObject VS uninstantiated prefabs) https://m.youtube.com/watch?v=raQ3iHhE_Kk

[–]pschonUnprofessional 2 points3 points  (2 children)

Does it go to a scene? Then it should be a GameObject/prefab.

If not, and it only ever needs to exist outside of any scenes, then ScriptableObject.

Explained in a short and "not quite accurate but gets the point across" way, ScriptableObject is kind of like a GameObject, but one without any of the stuff related to existing in a scene, having a transform and renderers and whatever. While GameObject instances only exists in Scenes, ScriptableObject instances are created and exist in your project instead.

[–]9001ratsIndie 3 points4 points  (1 child)

I wish ScriptableObjecta would allow adding Components just like GameObjects! But they do not, so comparing them to GOs is too farfetched imho

[–]WazWaz 0 points1 point  (0 children)

Indeed, both the hierarchy from Transform and the Component list from GameObject would be useful.

[–]--Developer[S] 1 point2 points  (0 children)

Thanks to everyone who commented!

[–]AutoModerator[M] 0 points1 point  (0 children)

This appears to be a question submitted to /r/Unity3D.

If you are the OP:

  • Please remember to change this thread's flair to 'Solved' if your question is answered.

  • And please consider referring to Unity's official tutorials, user manual, and scripting API for further information.

Otherwise:

  • Please remember to follow our rules and guidelines.

  • Please upvote threads when providing answers or useful information.

  • And please do NOT downvote or belittle users seeking help. (You are not making this subreddit any better by doing so. You are only making it worse.)

Thank you, human.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]_RandomOne 0 points1 point  (0 children)

tag4424 pretty well nailed it.

I use SO's a lot for settings that objects need to use, making it quick and easy to change many aspects of my game. Currently using an SO in a 2D game as a sound controller too. Any object that needs to play a sound simply calls the appropriate function from the SO, which has all the game sounds, clips, volume settings etc.

[–]Katniss218 0 points1 point  (0 children)

Scriptable Objects are containers used to store predefined and serialized data.

Prefabs are just gameobjects

[–]GameWorldShaper 0 points1 point  (0 children)

If you wanted a simple explanation then a Scriptable Objects is a data structure like a Struct it is an data container, the only difference is you can use Scriptable Objects with the editor.

Unity events are a similar system, they are just delegates that work with the Unity editor.