• 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 angusmf · Apr 27, 2015 at 08:37 PM · reflectioncomponents

GetProperties returns Unity props instead of my class

Unity 5.01. I have an object Owner (of type object) that is a reference to an instance of my Breed class, derived from MonoBehaviour. Calling GetProperties on any permutation (cast, "as Breed"'d, directly on the Owner object, "this" from the actual class, GetComponent from the actual class) of the Owner object returns some Unity props, like audio, light, etc. Gleaned from the Monodevelop debugger. The Owner property shows of the props I actually want to see, but the array of PropertyInfo is different.

example:

 public class Breed : MonoBehaviour {
 
 //loads of bools, strings, etc. of many different levels of accessibility

 //here's the problem--no accessors. If I had included this in my example someone would have figured this out
 public int example1;
 
 void Update () {
 
 //no good!
 
     if (getprops) {
 
         PropertyInfo[] piArray = this.GetType().GetProperties();
 
     }
 
 }
 
 }



Comment
Add comment · Show 3
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 Bunny83 · Apr 27, 2015 at 09:21 PM 1
Share

After reading your description the third time i concluded that i have no idea what you're talking about ^^. You seem to mix certain terms in strange ways. What "owner object" are you talking about? where is it? Is it an actual object? or is it a field / variable? maybe also a property?

You use GetProperties without any binding flags, so you only get public properties which are declared inside this class. No private / protected / internal properties.

Could you please edit your question, fix the formatting of your code and include relevant parts of your code. Since you want to use reflection to access properties, it might be useful to see how those are declared. And you should probably rewrite / rephrase that whole "owner object" thing because i have no idea what that has to do with the showed code.

edit
GetProperties without BindingFlags seem to return all properties, even the derived ones. However that's only true for public properties.

As said i don't get what your actual problem is. What exact do you expect and what do you get?

avatar image siaran · Apr 27, 2015 at 10:13 PM 0
Share

I'm...fairly sure that this.GetType().GetProperties() doesn't do what you expect it to do. Altough to be fair, I have no idea what it is you're expecting.

avatar image angusmf · Apr 28, 2015 at 12:40 AM 0
Share

Updated my example to show I was trying to get properties on a field.

The "Owner object" is an object Owner (of type object), so I guess the answer to your question is "actual object." And as the answer I submitted says, I wasn't expecting the inherited properties. That's all.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by angusmf · Apr 28, 2015 at 03:22 AM

This basically led me to figuring it out: http://answers.unity3d.com/questions/730181/c-reflection-getproperties-returning-unwanted-info.html

I didn't expect the derived properties and I wasn't paying attention to the difference between a field and a property. It seemed like I was somehow repeatedly calling GetProperties on the wrong object behind the scenes, regardless of how I accessed it because I kept getting the same set of properties.

I'd say thanks for the help, but I just got the "I don't understand your question, but that won't stop me..." stuff I expected.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating a mirror effect 1 Answer

transparent + reflection shader (river water problems) 2 Answers

Iphone Shader Reflection Map 0 Answers

How to reflect an object. 1 Answer

Call c# script function from managed c# script in dll 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