Unity Build Error

Options
Rawa
Rawa

So I am trying to build my Unity game and every time I do it, I get an error saying CS1022: Type or namespace definition, end-of-file expected. I clicked on it and it takes me to part of my Unity Photon Network script at the very end near the last endif. VScode doesnt count it as an error but unity tells me that an end of file is needed. I put in a #endif and I get an error. There aren't any extra '}'. It takes me to the highlighted area at the very end of the script (the bold one)

          Component.DestroyImmediate(photonHandler);

        }

      }

    }

#endif

  }

}

Answers

  • tleylan
    Options

    VS Code should/will definitely show that there is an error. It may not be correct in guessing where. Unity is simply telling you there is an error.

    The way I would find out where it is (if it wasn't obvious after staring at it awhile) is to comment all the code in the class out so there is just the class definition. They start uncommenting obviously correct code until the error returns.

    There is no way for future reference BTW for anyone to determine where the problem is when you show the last 6 or 7 lines.

    You'll find it just divide and conquer until you see it.

  • Rawa
    Options

    @tleylan I checked it out and Unity is saying that it it shown on line 3296, the last line I was showing, where only a '}' is

  • tleylan
    Options

    @Rawa Unity must be mistaken. The program is parsed and a parser can get confused trying to match braces (and other pairs) when one is missing.

    Again I suggest that you comment out most of the code until there is no build error and then uncomment part until you see it again.

    Trust the compiler, the problem is in your code.

  • Rawa
    Options

    I fixed it, I didn't fine the problem but I just copied an older script and it worked

This discussion has been closed.