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
0
Question by ungalyant2 · Sep 06, 2013 at 10:50 AM · editorfunctionspublic

Finding all public functions on a game object

I'm trying to write a script for dialogue, and I want to it be able to check against public variables/functions, akin to how Unity Animations can find any public functions on an object. I was just curious if there's any known way to achieve this? Or whether it would be shorter to manually code for each possibility.

Comment
Add comment · Show 6
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 ShadoX · Sep 06, 2013 at 12:02 PM 0
Share

Out of curiosity. Why would you want to do that?

avatar image ungalyant2 · Sep 06, 2013 at 12:12 PM 0
Share

So that for the sake of checking against various outcomes, such as how many coins a player has, rather than having to code in the script for each and every possible value in each and every possible script I would want to check against. I could simply drag in an object, choose the public function on it I wish to check against, and enter a $$anonymous$$imum requirement based on the returned value type.

avatar image flaviusxvii · Sep 06, 2013 at 01:08 PM 0
Share

Sounds like you are trying to use the object itself as some kind of organizational data structure. You should use constructs that are made for holding/looking up data, like List and Dictionary.

avatar image Jamora · Sep 06, 2013 at 01:12 PM 0
Share

This is exactly what the strategy pattern is all about; choosing the correct behavior (during runtime) for a given situation, then applying that behavior to the situation.

All you need is an interface that you implement in all classes you need the behavior on. Then use this function to get access to it and call your function.

The more I read your above comment, the more it sounds like you want behavior, but you don't want to code it. That's an impossible equation.

avatar image ungalyant2 · Sep 06, 2013 at 01:21 PM 0
Share

I don't believe the system I'm looking for is impossible. Like I said, it's the exact system implemented in a Unity animation, where the object upon which the animation is done, can have all its public functions accessed through the editor, by the animation itself. I just wanted to know if such functionality for an editor could be readily replicated.

Show more comments

1 Reply

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

Answer by Jamora · Sep 06, 2013 at 11:12 AM

If your system is not terribly complex, maybe a text box with a few different strings shown, it might be best to manually code it all.

If your system is complex: different behaviors for texts, restrictions or other rules that apply. Manually coding that all doesn't sound like a very good design decision. You should take a look into polymorphism and the strategy pattern.

If you still feel a need to access individual functions from classes, you can use reflection to gather all kinds of information about classes, including fields and functions. And even then, you need to somehow (Attributes)apply context information to these fields and functions to allow the computer to choose the correct one. After all, to the computer, it's all 1s and 0s. Reflection is slow and might not work on all platforms.

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 ungalyant2 · Sep 10, 2013 at 08:47 PM 0
Share

after looking further into reflection (although not fully understanding it) this does generally appear to achieve what I want it to do. I can access any members or fields of a type purely by the name of that member/field. The only problem being that this does not allow me to change the values of members as far as I can tell, meaning I am unable to access inherited variables.

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

18 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

Related Questions

How to get a ONLY the INSPECTOR variables that can be modified. 0 Answers

Mixamo Animation and Animation Editor 1 Answer

Exposing interface implementation 3 Answers

Unity Editor, Linking script functions 1 Answer

Auto generated script with more functions? 0 Answers


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