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 Vampiressae · Feb 19, 2014 at 10:08 PM · inspectorfloatvectorvalueslinking

Link a value to another value in the Inspector

Hello I haven't find anything on this so I thought I'll give this a shot: I have a script (Transformer) which takes a float and alters it (with perlin noise, sinus, etc.). I put this script on a GameObject. How can I link let's say the Y rotation of the GO to this float in the script via Inspector? Thing is I don't always want to alter the Y rotation but maybe a light's intensity or a scale or anything else. so I need to be able to link values (floats, Vectors) dynamically, like I'm able to do with textures, gameobjects etc. etc by drag & drop.

Thanks in advance!

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 Ed unity · Feb 19, 2014 at 10:29 PM 0
Share

As far as I know you cannot link variables of a component to other variables of another component attached to the same object. While you can access those variables in the script, that is coded into the script and changing the variable dynamically is not something that is readily possible.

1 Reply

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

Answer by whydoidoit · Feb 20, 2014 at 05:03 AM

You could create a component that runs in Edit Mode ([ExecuteInEditMode]) that you use to make the links, there is nothing built in to do that but it could be a very useful script if you want to link things together in this way. If you used reflection to get and set the values then it could be quite flexible - the only problem being that changing just one part of a Vector3 would probably need a specific code path.

  1. Create a class flagged with ExecuteInEditMode

  2. Create two Component references for source and target

  3. Create two string variables to describe the value to read and the value to set

  4. Use reflection to get the FieldInfo for the source and target properties on the objects

  5. Check for changes in the Update function of the new class and apply changes

Clearly this would be simple if you just linked a direct value - the code path for a Vector3 involves reading the vector, updating the component and writing it back again - this happens with anything that is a struct (value type).

Comment
Add comment · Show 4 · 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 Vampiressae · Feb 20, 2014 at 09:10 AM 0
Share

Thanks a lot for the tip! I'll check it out once I have the time. If it's complicated to alter only 1 value of a Vector3, I'll pas the whole vector :) I'll check out this whole "reflection" and "ExecuteInEdit$$anonymous$$ode" deal. If I find out, this is what I'm looking for, you'll have my gratitude (and the karma) :)

avatar image Vampiressae · Feb 20, 2014 at 07:40 PM 1
Share

Yep, that solved the problem. Though I thought I would rather make it in the conventional way. Reflecting several dozen values per frame, I imagine, could be much more detrimental than running more lines of code in a dozen instances of a script :) Thanks anyways! $$anonymous$$udos!

avatar image whydoidoit · Feb 21, 2014 at 01:58 AM 0
Share

Yep reflection isn't fast. Ok during setup but best to limit it per frame.

avatar image Vampiressae · Feb 22, 2014 at 09:00 AM 0
Share

I ended up making 1 base class that handled a float modification by various modes and other classes that are extended to this class and use its functions. One class for every aspect I want to change (position, rotation, scale, material color, light color/intensity, etc.) Only I have a little concern: is accessing a custom value of a material like GetValue("_Color") SetValue("_Color") the same as reflection? I mean I access it by a string... I reckon it might be as slow as reflections...

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

20 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

Related Questions

NullRefenceException Using Arrays 2 Answers

Floating-point errors while assigning transforms 1 Answer

Can't assign dictionary values 0 Answers

Unity4 Ignoring Inspector/Initialized Public Value in Build 1 Answer

Arrays and the inspector 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