Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by sdgd · Oct 27, 2013 at 01:01 PM · accessmakeuse

how to make/use ScriptableObject?

I've been trying to solve a mans Question Learned I cannot help him any longer but out of curiosity I went looking in link @meat5000 provided and I found something I've never saw ScriptableObject before

A class you can derive from if you want to create objects that don't need to be attached to game objects. - am what? how do I make 1 if it is not attached to non GameObject, IF I manage 1 how do I access it?

  • This Answer Says he can make 2.35M Scriptable Objects before Unity Crashes

  • also I've been looking through this

  • and this it has a code in it and I don't understand more than 40% of it

also I've been asking my self:

  • How to create 1?

  • how to keep track of ScriptableObjects?

  • how to access them?

  • where could I see each scriptable Object in hierarchy?

  • IF it's made and it has MeshRender attached where will it render it? if it has not got Transform attached?

this Question is made purely out of curiosity.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Oct 27, 2013 at 04:55 PM

I guess the idea is to have an object that is not a component. So it is in memory like any object but not on any GameObject. Meaning you won't see it in the Inspector nor in the Scene list.

You create one like this:

 public class NewBehaviourScript : ScriptableObject {
 int a = 10;
 
 public int A{
     get{return a;}
 }
 }

and you use like this:

 public class Trial : MonoBehaviour {
 NewBehaviourScript newGuy;

 void Start () 
 {
     newGuy = (NewBehaviourScript)ScriptableObject.CreateInstance(typeof(NewBehaviourScript));
     print(newGuy.A);
 }

}

You keep track of it via the reference you assign it to. Just like basic programming. It is just a storage class for values and methods, I don't think it is meant to have a mesh. It does not seem to have any update so you would have to update via your own call.

If you look at the inheritance hierarchy it has nothing to do with the whole MonoBehaviour apart from being an Object.

So, it is just for storing info and helpers.

My point of view.

EDIT: it then makes sense to be able to create millions of them since they are just taking space in memory but no resources, no update call, no Unity maintainance, only GC when needed.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sdgd · Oct 27, 2013 at 08:13 PM 0
Share

thanks you've been very informative :)

it can be done like this too right?

 public NewBehaviourScript newGuy;

so it actually isn't an object

but different kind of class

since you have to call it from $$anonymous$$onoBehaviour

but somehow calling it is much more complex than class or even structure

I usually was using a class for this

I wander what would they be using millions of ScriptableObjects for, ...

avatar image fafase · Oct 27, 2013 at 08:24 PM 1
Share

It is an object and it is not called from $$anonymous$$onoBehaviour. It actually has nothing to do with $$anonymous$$B. It is parallel to it on the engine inheritance.

  public NewBehaviourScript newGuy;

This is just a reference, but no data.

 newGuy = (NewBehaviourScript)ScriptableObject.CreateInstance(typeof(NewBehaviourScript));

will find some memory, create the object and store the address into newGuy.

Somehow it is the same as:

 newGuy = new NewBehaviourScript();

For some reason, Unity provide a fake ctor with CreateInstance probably because they have internal maintenance on the object.

The reason why you should use ScriptableObject over basic object is long explained here: http://answers.unity3d.com/questions/190350/what-is-the-purpose-of-scriptableobject-versus-nor.html

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What is Accept Rate 1 Answer

Setting folder rights using DirectorySecurity gives 'This platform is not supported' error 0 Answers

small example sendmessage from javascript to C# wrong??? 1 Answer

Can't Access a Prefab 2 Answers

Accessing scripts from another script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges