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 indGaming · Mar 18, 2012 at 04:55 AM · androiderrorbuildbuild-errorcomponent

BCE0019: 'ButtonAction' is not a member of 'UnityEngine.Component'.

ButtonAction is a function of a script..

 LinkedObj.GetComponent("Int_" + LinkedObj.name).ButtonAction(); //Calls Int_Object's ButtonAction function

As you see.. I MUST use the string parameter of GetComponent but I need to make it work on Android. All the loop-holes were using the Type parameter instead of String. I need a way to get it work as a string or convert ("Int_" + LinkedObj.name) into a component type.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by rutter · Mar 19, 2012 at 01:00 AM

Unity doesn't support dynamic typing when porting to Android. If you're planning to go mobile, you should always include #pragma strict at the top of your JS files. I'd personally recommend doing this, anyway.

Quick and dirty solution: `SendMessage()`:

 LinkedObj.SendMessage("ButtonAction");

If you're interested in object-oriented programming, it offers a simple and performant solution: create an abstract "button" class with a virtual ButtonAction() method, so that you can create a variety of buttons which each do different things but can all be activated in the same way:

 LinkedObj.GetComponent(MyButtonParentClass).ButtonAction();

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 indGaming · Mar 19, 2012 at 01:35 AM 0
Share

Thank you. What is the reason for using #pragma strict? Also, I do know a good amount on OOP. I learned a lot about it when I created an RPG in $$anonymous$$S Visual Studio's Visual Basic when I was younger. Also the button isn't like a gui button, its a activation button in-game like a swtch or lever. But that clas idea should still work but its not what I'm ai$$anonymous$$g for, I read more into that Send$$anonymous$$essage method and it will work fine for using any linkedobj ill be using. Again thank you.

avatar image rutter · Mar 21, 2012 at 08:34 PM 0
Share

#pragma strict forces the compiler to treat your code more carefully -- for example, you'll get more warnings and errors when you access variables or functions that don't exist. Sometimes this can slow down your development a bit, but it can also catch problems that would prevent you from deploying to other platforms.

In particular, dynamic typing is disabled when you're in strict mode.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Gradle build faild. see... error "in unity 2020.1.4f1!!!" 0 Answers

Error building Player: CommandInvokationFailure: Failed to re-package resources - Unity Android 2 Answers

Failed to re-package resources (Android build) 0 Answers

Android Build Error 1 Answer

APK is installed but does not show the application and does not open either. 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