- Home /
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.
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();
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.
#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
![](https://koobas.hobune.stream/wayback/20220613065239im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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