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 Levantez · Jan 28, 2014 at 04:06 PM · variableserializationscriptable object

Can Scriptable Object be use for this?

Hi, let say that there is a Character.

The character has a Component A, with member variable a and b.

Initially, these variables are initialized inside the components.

However, as more character got added, the variables are supposed to be the same for all characters. As such, the variables got refactor to a reference objects instead.

Instead of making a GameObject, thus having a need to brought it across scenes, Is it possible to store the variables inside an Object that will be reference across all scenes?

Also, the variables must be able to get edited via Window Editor.

//////// Edit, summarize rephrase the Question

How do I create a Scriptable Object? How do I edit it via editor? and how do I reference the variable inside it from a component?

//////Add one more question,

With ScriptableObject, If the variable got edited during runtime, will the change be permanent? Or will it got reset after Game Restart?

For example, there is weapon with ATK 100, then it got upgraded to ATK110, in this case I want the change to be permanent.

If it will get reset, is it possible to make it permanent?

Comment
Add comment · Show 1
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 MrSteve1 · Jan 28, 2014 at 04:07 PM 0
Share

You can always use AddComponent to attach scripts to new gameObjects

2 Replies

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

Answer by Xtro · Jan 28, 2014 at 04:44 PM

Definitely you can use ScriptableObject for this purpose.

You have to do three things.

1) Implement a class from ScriptableObject and put your variables in it (public)

2) Create an instance of the class in the project structure and fill the values in it.

3) Reference to that object where ever you need it.

Example of implementing the class:

 public class ExtraProjectSettings : ScriptableObject
 {
     public string WalkableTag = "Walkable";
     public string CameraZoneTag = "Camera Zone";
     public ParticleSystem TouchCircle;
     public QualityLevel[] QualitySettings;
 }

Please refer here about how to create an instance of your scriptableobject http://wiki.unity3d.com/index.php?title=CreateScriptableObjectAsset

Comment
Add comment · Show 1 · 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 Levantez · Jan 28, 2014 at 07:19 PM 1
Share

Thank you Xtro, this is exactly what I needed!

I've also edit the main question and asked an extended question.

avatar image
0
Wiki

Answer by ZebraJoe · Jan 28, 2014 at 05:43 PM

It sounds like you might want to make a "Game Manger Script" that your other objects or charters can reference. You could then add a :

DontDestroyOnLoad (this);

In the Update of the Game Manger Script so that the variables within that script will remain constant.

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

21 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

Related Questions

Change values of variables in System.Serializable 1 Answer

Serialize a list of scriptable objects to Json 0 Answers

Make the same serialized class as a ScriptableObject? 1 Answer

Cannot see serialized object's fields in Inspector 1 Answer

[SOLVED] How do I change the values of an HDRP Volume Profile at Runtime? 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