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
2
Question by Noktai · Dec 21, 2014 at 10:04 AM · prefabscriptableobjectdatainstance

"Prefabs" for classes, scriptableobjects?

I ran into ScriptableObjects recently, but I am not sure if I understand them correctly. In my case I have an Attack class, which holds a timeline with frame data on which hitboxes should be spawned, etc.

alt text

I have written an editor extension to manipulate the timeline, add frames, determine framerate, etc. Since this class is not a component, and it simply holds data, I thought it would be handy to let the extend the ScriptableObject class.

alt text

Everything went fine until I actually wanted to use the damn thing in runtime. I have a component that wants to get a copy (instance?) of this Attack class, with all the values that have been saved into this Scriptable Object so it can playback the Timeline class during an attack.

However, whenever I try to use ScriptableObject.CreateInstance(), all the fields are null.

alt text

Maybe I've misunderstood, and the ScriptableObject is only used to store data, and I should just feed the data manually into a new Attack class instance that I create in the component.

I'd like to simply use this ScriptableObject as some sort of prefab for a class, just being able to get a copy of the Attack with the variables as listed, and then directly reference the instance in the component.

Am I trying to do something unintended, should I somehow use a prefab for this, or did I simply implement the ScriptableObject incorrectly?

Thanks!

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

2 Replies

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

Answer by Noktai · Dec 23, 2014 at 12:55 AM

Turns out this works, as for as I've tested for now Attack attackCopy = Instantiate( attack ); //where attack is the reference to the scriptable object

Comment
Add comment · 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
0

Answer by RudyTheDev · Dec 21, 2014 at 01:15 PM

CreateInstance<> creates a new instance. It won't have your data. You ought to reference the existing asset with the script like you would a GameObject. Then access its members. This makes sense because you can have >1 asset with the same ScriptableObject class type.

As far as I'm aware, there is no easy way to copy the instance, you would probably need to use AssetDatabase, which is editor-only anyway. ScriptableObjects are best thought of as data containers that don't get changed at runtime.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I instantiate a prefab B in same place prefab A? 1 Answer

How can I set the material on an instance after creating it? 1 Answer

is having a Prefab reference inside a a Scriptable Object legit? 0 Answers

Change material inside instanced prefab, gameobject.renderer is NULL 1 Answer

How can I link a GameObject instance to a script variable in a Prefab using the editor? 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