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 /
avatar image
0
Question by sean244 · Dec 21, 2017 at 04:15 AM · editorinspectorpropertiesserializefield

If I have a bool method, how can I see in the inspector whether it returns true or false?

I know that bool variables can be public or use SerializeField to show up in the inspector, but what about a bool method? How can I see in the inspector whether that method returns true or false?

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 uk007singh · Dec 21, 2017 at 04:26 AM 1
Share

You can do like this: public class A : $$anonymous$$onoBehaviour { public bool bl=false; void Start() { bl=show(); }

  bool show()
  {
   return true;
  }
 }

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mazer83 · Dec 21, 2017 at 04:21 AM

You don't. The inspector can't show you what values methods are returning. If you want to see that, use the debugger. Using monodevelop, place a breakpoint (F9 on the line) where the method is being called, press F5 to connect the debugger to Unity. Run your game in unity with the play button. When the method gets called, the program will halt execution at your breakpoint, and you can step through the lines of code bit by bit with F10. You can hover over variables to see what they are. Press F5 again to continue the program as normal.

Comment
Add comment · Show 3 · 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 sean244 · Dec 21, 2017 at 04:37 AM 0
Share

I tried to mark your answer down, but apparently I need a reputation of 100 to do that. There are much easier ways of figuring out of the return value other than the one you just explained. I can have the method do a Debug.Log print, or even easier, I can just set a public bool to equal the method.

avatar image Mazer83 sean244 · Dec 21, 2017 at 04:54 AM 0
Share

The debugger is an excellent tool that every programmer should know how to use, Not only is it actually very easy to use, I find it much easier than using Debug.Log to find out what's going on behind the scenes. I don't think what you're asking for is possible with the inspector, which is why I told you about the debugger.

avatar image DreadKyller Mazer83 · Dec 21, 2017 at 05:05 AM 0
Share

@$$anonymous$$azer83 what sean is talking about is that they can set the value of a public variable to the value of the function inside the update, fixed update, late update, etc functions and then that will update it's value in the inspector for runtime. Do durring runtime yes, the inspector can do what they want just fine. In edit mode it can too, using either [ExecuteInEdit$$anonymous$$ode] or custom inspectors.

avatar image
0

Answer by DreadKyller · Dec 21, 2017 at 05:03 AM

Mazer83's answers is also not correct. A standard view of the inspector can't display the value of a function. And to set the value of a public boolean would require some point of entry that updates whenever a change is made. During runtime this isn't a problem, however if you wish to display this value outside of runtime, while editing, then you'll have to deal with custom editors. These are scripts that allow you to manually draw the inspector window for a specific component type, they provide far more powerful functionality for editing, however are more complicated to design. https://docs.unity3d.com/Manual/editor-CustomEditors.html

Alternatively as that page also describes, you can add the [ExecuteInEditMode] to have the script get ran while not playing, depending on the complexity of the script this may or may not be a good option.

Although as for Mazer83's answer, while Debug.Log and setting the value during runtime will work fine for you in this case, it's still a very wise choice to get used to the debugger, because not all problems can be solved with simple logging, and even if a problem can be, often times the debugger is far, far more powerful. People wouldn't have designed debuggers if printing to console solved everything.

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 Mazer83 · Dec 21, 2017 at 05:17 AM 0
Share

"$$anonymous$$azer83's answers is also not correct. A standard view of the inspector can't display the value of a function."

In your first sentence, you say I'm incorrect, but the next one indicates that I was correct; you can't get the return value of a method by looking at the inspector.

avatar image DreadKyller Mazer83 · Dec 21, 2017 at 05:27 AM 0
Share

Read the rest of my reply please, because you say the inspector can not display values of a function. This is incorrect. the default inspector window can not, Custom Editors Are still inspector windows, they override the rendering of the inspector and they can indeed display values of functions.

You also go on to explicitly say "I don't think it's possible to do this with the inspector" yet while the game is running you can set a variable to the value of the function inside the Start() function. These are two ways that the inspector CAN be used to display the value of a function, they are simply not default. Conflating the inspector in it's entirety, and the functionality provided without additions is where you are running into problems here. You are correct that the standard inspector layout that is generated automatically when no custom editor is found can not display the value of a function by itself, you are wrong that the inspector itself can not be made to display such values when told to.

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

99 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 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

Custom names for variables (array-elements!!) in the inspector?? 3 Answers

Fill/populate [SerializeField] automatically via script in editor mode? 3 Answers

Showing properties from a base class in inspector? 0 Answers

setting the properties in the inspector 1 Answer

Custom Inspector. Aligning properties? 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