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
0
Question by ahmoudy2000 · Sep 03, 2020 at 09:29 PM · serializationscriptableobjectscriptable objectdata storage

Best way to create runtime variables for Scriptable Objects?,What's the best way to create 'runtime values' for Scriptable Objects?

By runtime variables I mean temporary variables that can be edited on runtime without changing Scriptable Object's original values. Think object states, player HP, etc. My project has it so that you can set scriptable object values through a custom inspector in the editor, and these values would be used and edited on runtime.

I'm honestly stumped on how to do this. I've tried instantiating each SO on start but that created a whole slew of issues like not being able to grab objects by reference and instead having to search for their copy. I've thought of copying every single variable in said object on Awake, but I'm not sure that's viable.


What's the best way to go about this? I've searched long and hard on ways to keep original SO values in runtime but I haven't found any good ways to do it. ,By runtime values I mean variables that temporarily store data at runtime so the original variables of the SO aren't permanently changed even after I close the game. The data gets edited on runtime

What I'm currently doing is straight up instantiating the object and storing that instead, but this causes a whole slew of issues like not being able to reference the object directly and having to search for its copy.

I'm wondering if it's a viable idea to make a copy of EVERY SINGLE VARIABLE and initializing them in Awake(). I'm honestly stumped because all solutions for this involve a lot of effort and messy code.


What's a good way to use SOs where its values change on runtime? I'm looking for any workarounds or ideas in general.

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
0

Answer by ShadyProductions · Sep 03, 2020 at 09:35 PM

Sounds like your design is flawed, scriptable objects are data containers. That contain data for your actual game objects.

Etc a Card class with color and type of card as string. (Actual game object)

then you have a Card scriptable object for each card with image or something and type + color

and you loop over these data containers, and create your cards based on them

 var cards = new List<Card>();
 foreach (var cardData in cardScriptableObjects)
 {
     var card = new Card(cardData.Color, cardData.CardType, cardData.CardImage);
     cards.Add(card);
 }

You don't use the scriptable objects as gameobjects.

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

147 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make the same serialized class as a ScriptableObject? 1 Answer

Serialize a list of scriptable objects to Json 0 Answers

Scriptable Object's Data Gets Lost After Re-opening Unity!!! 1 Answer

Why do I need to serialize a struct inside a ScriptableObject to save its data? 1 Answer

What are the pros and cons of ScriptableObjects vs. JSON for data files? 2 Answers


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