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
1
Question by absameen · May 17, 2012 at 02:43 PM · reflectionerror-handling

Reflection Ignore Unsupported Properties

I am using reflection in an editor script. The script looks up all of the components on a GameObject and returns their properties with GetProperties();

Some properties are obsolete and return an error when used in conjunction with GetValue such as:

 minVolume is not supported anymore. Use min-, maxDistance and rolloffMode instead.
 System.Reflection.MonoProperty:GetValue(Object, Object[])

How can we check for these obsolete properties or simply avoid having to see these error messages?

 try{ 
   propertyValue = propertyInfo.GetValue(myComponent,null); 
 } catch {
   // is not catching the error
 }

Edit: The problematic properties I've found were "rolloffFactor","minVolume", and "maxVolume" which are all from AudioSource. My current workaround is to check for these property names and skip them.

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

2 Replies

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

Answer by whydoidoit · Jun 25, 2012 at 12:09 PM

You need to use:

 if(!propertyInfo.IsDefined(typeof(ObsoleteAttribute), true))
     propertyValue = propertyInfo.GetValue(myComponent,null); 
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 usernameHed · May 04, 2020 at 12:55 PM 0
Share

Doesn't work with for Animator and some other: "Setting and getting Body Position/Rotation, IK Goals, Lookat and BoneLocalRotation should only be done in OnAnimatorIK or OnStateIK"

avatar image
1

Answer by Synthesizer · Jun 25, 2012 at 12:06 PM

I accidently just posted some code first, but the idea is to look for an Obsolete attribute on your property.

Here's some more info: http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.getcustomattributes.aspx

And a code snippet:

 object[] attr = propertyInfo.GetCustomAttributes (typeof(ObsoleteAttribute), true);
 
 if(attr.Length > 0)
    continue;
Comment
Add comment · Show 2 · 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 whydoidoit · Jun 25, 2012 at 12:53 PM 0
Share

You are better off using IsDefined though - there's no array allocated so it removes the chance of extra GC ;)

avatar image Synthesizer · Jun 25, 2012 at 01:04 PM 0
Share

Ah, good to know, thanks :)

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# Reflection GetProperties returning unwanted info 2 Answers

Reflection probe problem: reflection shifts in wrong direction when camera moved 0 Answers

Problem with reflection probe 0 Answers

Get List of Signatures of Messages to Monobehaviour 1 Answer

Fragment Shader pixel gets overwritten 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