- Home /
Getting a huge amount of errors regarding contained definitions in GameObject
I'm fairly new to Unity, but this one strikes me as particularly weird. Suddenly, all my scripts are getting similar errors. Here's a snippet of one of them:
GameObject b = Instantiate(arrayOfPrefabs[i] as GameObject); //Cannot convert from 'GameObject' to 'UnityEngine.Object'
b.transform.SetParent(transform);
b.transform.position = transform.position; //'GameObject' does not contain a definition for 'transform' and no accessible extension method 'transform' accepting a first argument of type 'GameObject' could be found
Color c = b.GetComponent<Image>().color;
c.a = 0;
b.GetComponent<Image>().color = c;
if (b.GetComponent<Text>())
{
c = b.GetComponentInChildren<Text>().color;
c.a = 0;
b.GetComponentInChildren<Text>().color = c;
b.GetComponentInChildren<Text>().text = "sdf";
//'GameObject' does not contain a definition for 'GetComponentInChildren' and no accessible extension method 'GetComponentInChildren' accepting a first argument of type 'GameObject' could be found
}
In some of these there's also the following quote: "(are you missing a using directive or an assembly reference?)", but my using statements are the same as they were when this code worked, it kind of happened all of the sudden, all at the same time. I tried reimporting all assets but it served for nothing. I'm absolutely lost, any help would be greatly appreciated.
Answer by Hellium · Mar 23, 2019 at 10:40 PM
Are you sure you haven't declared a class called GameObject
in your project?
this is the error for sure. try changing GameObject for UnityEngine.GameObject, if it works search for your custom GameObject class
That was it, I must have panic-clicked some suggestion in VisualStudio and couldn't find it among the other stuff. Thanks a lot.
Now, I'll go repeatitively headbutt a wall or something.
Your answer
Follow this Question
Related Questions
Raycast to Disable Script 0 Answers
NULL REFERENCE EXCEPTION,NULL REFERENCE EXCEPTION while accessing child objects unity2D 0 Answers
Getting errors when referencing a variable. 1 Answer
GameObject not working with variable in C# script 3 Answers
How to mark the vertices on a mesh and make the markers follow them as you apply transformations 0 Answers