- Home /
Error code CS0029.
I get the compiling error CS0029 about converting Transform to GameObject.
This is the relevant part of my script:
Handle = this.gameObject.transform.GetChild(0);
HandleExtra = this.gameObject.transform.GetChild(1);
BladeHolder = this.gameObject.transform.GetChild(2);
Blade = this.gameObject.transform.GetChild(3);
Any help is appreciated.
You are not providing the full error.
You are not providing the full code.
You are obviously referencing a Transform where your code is expecting a GameObject and it is unable to convert it to one. $$anonymous$$ore than likely because GetChild() returns a transform. So the solution might be...
Handle = this.gameObject.transform.GetChild(0).gameObject; HandleExtra = this.gameObject.transform.GetChild(1).gameObject; BladeHolder = this.gameObject.transform.GetChild(2).gameObject; Blade = this.gameObject.transform.GetChild(3).gameObject;
Answer by Trevdevs · May 13, 2017 at 01:57 AM
Judging by the error the varibles Handle, HandleExtra, BladeHolder and Blade all are GameObjects
.GetChild refers to the Transform of that object not the GameObject as seen here in this documentation https://docs.unity3d.com/ScriptReference/Transform.GetChild.html
if you want to assign Handle and everything else to its respected GameObject it will look like this for each
Handle = this.gameObject.transform.GetChild(0).gameObject;
Hope this helps :)