- Home /
Error cs0029: Cannot implicitly convert type `void' to `bool'
I was coding and suddenly this error popped up:
Error cs0029: Cannot implicitly convert type void' to
bool'
I checked over my code but I couldn't find anything wrong with it (Its just three lines and a comment) and I realized I needed help from the pros. So please help me figure out what is wrong.
Here is the code:
void Update() {
if(gameObject.SetActive(false)){
//yield return new WaitForSeconds(5);
transform.position = new Vector3(Random.Range (-35,35), 2, Random.Range (-55,17));
gameObject.SetActive(true);
}
}
Thanks For Reading This,
-SK
Answer by Bunny83 · Oct 15, 2015 at 03:01 AM
"SetActive" is a method to set the object active. That method doesn't return any value. Yet you put it in an if statement which expects a boolean value. Since SetActive has the return type "void" (which simply means "nothing") you can't put it in an "if" statement.
If you want to check if the object is active or not use activeSelf.
Your answer
![](https://koobas.hobune.stream/wayback/20220612041336im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Raycast Ray ray origin problem 3 Answers
Video Workaround in Unity 1 Answer
Quiz Scoreboard 2 Answers
Error CS0029 1 Answer
[Closed] Getting CS0029 error when I try to check position of an object 1 Answer