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.
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.
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.
Your answer

Follow this Question
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