- Home /
BCE0019: component is not a member of 'Object'
Project has thus far been compiling fine, ran into some issues that seem to be caused by not using #pragma strict when compiling for iOS, but "fixing" them has resulted with this:
Using the (slightly snipped) code
var selected; var master;
function update()
{
selected = master.GetComponent("Master_control").selected as Master_control;
}
results in "BCE0019: 'GetComponent' is not a member of 'Object'.", with tag and transform popping up later in the script for the same error.
I've tried casting as gameObject, GameObject, and Object to no luck, though I'm now confused on the difference between the first two.
Any ideas?
UPD1: New code:
#pragma strict var selected : GameObject; var master : GameObject;
function Update () {
selected = master.GetComponent.<Master_control>.selected;
}
Answer by Jessy · Jan 27, 2011 at 01:52 PM
m_r_d_e gave the answer. However, your script has other problems.
If master were a GameObject or Component, then what'd you actually need is
selected = (master.GetComponent("Master_control") as Master_control).selected;
But that uses the GetComponent that takes a string, which is no good. You could improve its performance by doing
selected = (master.GetComponent(Master_control) as Master_control).selected;
But that's long. Use the generic form, which is as yet undocumented. :-P
selected = master.GetComponent.<Master_control>().selected;
Thanks both. Oddly enough, Jessy's second suggestion works, but the first(and m_r_d_e's) return formatting errors("expecting ), found 'master'", etc).
The third also hasn't worked. I've updated the question with the code. It returns the errors: BCE0138: 'UnityEngine.GameObject.GetComponent' is not a generic definition. and BCE0019: 'selected' is not a member of 'error'.
The second error strikes me as quite odd but after three restarts(one of which was a full computer reboot), I'm thinking it's not a bugged out client.
Sorry, I forgot parentheses in the Generic form. Should be good now. I have no idea what's wrong with the first example; I can't reproduce that error.
That sorted it, thanks. The first is probably just the result of another mistake that works higher in the code.
Answer by mrde · Jan 27, 2011 at 10:44 AM
in your code master is Object, it must be GameObject or Component and then try this
selected = ((Master_control)master.GetComponent("Mater_control")).selected;
this is found to be a problem of $$anonymous$$e aswell, just defining the object as a GameObject fixed my issues.
Your answer
Follow this Question
Related Questions
Pragma Strict Question/Problem 1 Answer
dynamic typing in Unity iOS: ...not a member of 'UnityEngine.Component' 2 Answers
Unity 3.4 standard assets not working in iOS builds? 4 Answers
pragma strict issues with iOS 1 Answer
BCE0019: 'mesh' is not a member of 'UnityEngine.Component' on Android Build 2 Answers