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 yaroslav_ · Jul 19, 2018 at 12:02 PM · reflectioninheritancecopy-paste

how to apply same fields for objects with different script but inherit same class Unity C#

i have lots of classess who inherit BaseIsland (more then 20) each of classess have prefab and i wonna to fill a lot of fields with same value for each of them. but some of values type are like AnimationCurve some fields are with types of transform so how can i apply same Value to all of them?

probably i can create some object fill all fields and somehow using reflexion get these fields from that object and set these fields to each of them

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 Harinezumi · Jul 19, 2018 at 12:17 PM 0
Share

Probably a custom Editor script or EditorWindow could help filling in the same values, but I'm not sure what functions to use exactly or how much effort it would be. I'm sorry that I cannot be more specific.

One idea I have for this is that you create a custom EditorWindow (for example BaseIslandEditorWindow) which has fields for the values that you want to assign to all of your prefabs. Then you have button on it, which when pressed checks all the selected game objects ( Selection.gameObjects), and the ones that have BaseIsland component on them will get the values specified in the fields copied to them.

A different possible solution (but more work upfront) would be to move towards a data driven approach: you could move all the configuration data of a BaseIsland into a class derived from ScriptableObject, e.g. BaseIslandData, and use the values in it to set it up. Then you create data assets from BaseIslandData instances and just assign them to the different prefabs that have a script deriving from BaseIsland.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by madks13 · Jul 19, 2018 at 02:27 PM

If you have same values, use static properties.

Comment
Add comment · Show 3 · 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 Harinezumi · Jul 19, 2018 at 02:33 PM 0
Share

You cannot assign values to static properties from the Editor, which I think yaroslav_ wants to have.

avatar image madks13 Harinezumi · Jul 19, 2018 at 02:39 PM 0
Share

I don't see him saying it's from the editor.

avatar image Harinezumi madks13 · Jul 19, 2018 at 03:33 PM 0
Share

True, there it is not said explicitly, but AnimationCurve is mentioned, which is usually defined from the Editor (it is possible from code, but it is cumbersome and beats the purpose). I guess @yaroslav_ can tell us.

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

91 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

Related Questions

Building a Collection of Subclasses and Modifying Their Public Members from the Inspector 0 Answers

Get all inherited classes of an abstract class - Editor Scripting 1 Answer

I need an Array of System.type[] from all of my ScriptableObjects scripts 0 Answers

An OS design issue: File types associated with their appropriate programs 1 Answer

Get name of inherited type? 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