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 /
  • Help Room /
avatar image
0
Question by Or-Aviram · Sep 12, 2016 at 05:12 PM · inspectorpropertiesgetters

Why are getters getting called more than they should be called

I made a property, and I just made it in a very basic way. I also put a Debug.Log statement, to remind me later that I should continue the getter.

That Debug.Log statement is probably the best thing that happened to me... The console prints the message 4 times each time I go on an object that uses it in the inspector (using a custom inspector). It's an integer that I put in the inspector, so it should be called, so it can display it, but four times? It's also always four, no matter what.

If every time you get a property it calls it FOUR times then my game is probably VERY un-optimized, because sometimes I make getters that call methods like GetComponent.

EDIT:

I decided to add some more details, for anyone who does read long things. Here is the only line I got it at:

 EditorGUILayout.LabelField("Property", target.property.ToString());

This is an inherited property. There are two objects that inherit from it. Obviously, when I select a game object that has it, it gets called, because it gets the value so it can draw it in the inspector. But why four times?

Here is how the console looks, each time I got a group of messages is when I pressed a game object with a child script attached to it.

video

I waited a few seconds before each time I pressed, so sometimes it was called...in a drunk way. That two were first and then the other two. It's un-expectable, I really have now idea how it works, because literally the only line I got it at is at that editor line. Unless Unity does stuff behind the scenes.

Comment
Add comment · Show 2
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 NoseKills · Sep 12, 2016 at 09:52 PM 0
Share

Properties are a C# program$$anonymous$$g language feature just like methods and they get called just as many times as... as they get called. I mean there's nothing that would make a property get called 4 times if you call it once, whereas a method would get called once when you call it once. Unless you have some kind of recursion going on... Impossible to say witout seeing any code :)

If you see 4 log outputs when you click on an object that uses a custom inspector, that probably just means Unity wanted to draw the custom inspector 4 times so it needed to get your property's value 4 times (once on mouse down, once on mouse up, once for completing the click, maybe it was preparing for you to drag it... who knows. It's not really relevant why).

Custom inspector code is meant only for displaying and manipulating data in Unity Editor. It won't even go into the final build so it won't affect performance.

avatar image Or-Aviram NoseKills · Sep 13, 2016 at 11:59 AM 0
Share

I edited the question.

0 Replies

· Add your reply
  • Sort: 

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

69 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

Related Questions

Show in inspector other class properties 1 Answer

How do I see what Reference properties and Value properties I can address in GetComponent in C#? 0 Answers

Why does rotating via viewport give different values than inspector rotations? 2 Answers

Collider is deleting itself when I press play 0 Answers

Is there a way for a public/serializedfield to be uneditable and just grayed out in 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