Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 joseGuate97 · Jul 30, 2019 at 06:01 PM · uilayoutrecttransformscriptable objectproperty fields

How to Save Property Values of a Component on a Scriptable Object?

I would like to have two alternative layouts based on the configurations my users will select on settings - e.g., if playing the game on "super easy" the layout will be one, and if playing on "super hard" the layout will be another.


With Scriptable Objects, I could make the game objects on my scene know the values they should use based on the asset file that corresponds to the current difficulty - i.g., DifficultyConfiguration1 or DifficultyConfiguration2 files (from DifficultyConfiguration : Scriptable Object).

Now, I would like to avoid having to declare every single variable of every single property of any component, attached to a game object on my scene, that I want its properties to vary. For example, if I want the Rect Transform of a panel to vary (e.g., its width, height, pos x, etc.,), I would not like having to declare every single of them on my DifficultyConfiguration script. It would be just very tedious, because there are just enough panels that I want to readjust based on the values of my DifficultyConfiguration file.


This is what I attempted first, but then realized that it doesn't work because Assets cannot reference GameObjects in the scene.

  • To create a ScriptableObject where I could "save" the property values that I would like to use depending on the "current" DifficultyConfiguration file. alt text

  • But then, I can't drag the components from my scene onto my DifficultyConfiguration files (again, because Assets can't reference GameObjects on the scene - and this is how I realized it). alt text


But, actually, I never intended to reference any GameObject on my scene, as I explained. What I want is to hold a copy of the property values of the, for example, RectTransform components (of the relevant GameObjects) on my difficulty configuration files. Is that even possible? Or any ideas on how I can achieve a similar mechanism?

(Again, in the worst case, I would declare every single variable for every property value of each relevant GameObject; but ones are trickier than others, like the Anchor Presets. I don't want to go that way at all.)

unityanswers2.jpg (28.2 kB)
unityanswers1.jpg (34.2 kB)
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 Eldoir · Apr 09, 2020 at 07:54 AM

Hi,

Even if your question starts to get old, I guess it's still valuable since you got no answer. If I had to manage layouts depending on difficulty, I would put the layout into the ScriptableObject.

Something like :

 public class MyConfig : DifficultyConfiguration {
 
     public GameObject uiPrefab;
 }

Then, at the start of the scene, I would have a specific script whose role would be to instantiate the UI prefab of that difficulty file. That way, I could put everything I want into this uiPrefab, with as many GameObjects as I want, with lots of properties, in a complicated hierarchy.

I would have a base UIPrefab and then have a Prefab Variant for each difficulty to reduce the amount of work needed to propagate a change to every layout I've created.

I hope this helps!

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

186 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 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

UI LayoutGroup does not organize dynamically instantiated buttons 8 Answers

Fill empty space in parent in UI Layout 1 Answer

How do I layout dynamically instantiated UGUI components? 1 Answer

Horizontal Layout Group making a Scroll Rect's Content rect width to be negative 1 Answer

Stretching 90° rotated RectTransform to the size of the Canvas 0 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