CameraRaycaster won't find enum Layer-tried multiple solutions already

Using Unity 5.6.0f3 and no matter what I do (deleting and reimporting the raycaster script, deleting and recreating the utility script. shutting Unity down and starting up again, wrapping the enum in a namespace and using a using statement in the raycaster script) the raycaster script will not find the enum in Utility.cs.

Any help would be appreciated…

Hi @ChunkySoup,

Do you mean, the auto-complete feature won’t find it in the IDE (Mono / Visual Studio)?

Assuming so, can you please let us know which IDE you are using and post both of the scripts you have mentioned.


See also;

I am using VS 2017 Community edition. The error on the raycaster script is “The type or namespace name ‘Layer’ could not be found(are you missing a using directive or an assembly reference?)”

as an FYI both the Utility and CameraRaycaster script are in my Scripts folder in Unity

Utility.cs

CameraRaycaster.cs

I have just recreated that code in Visual Studio 2015 (appreciating the version difference) and it works without issue.

I know from previous experience with Visual Studio that sometimes it can get a little, confused, if things are not always built in an order it likes. You could try building before you try to use Layer. e.g. comment all references to the layer enum anywhere else (or the whole file if it won’t introduce other errors)… then run… that will ensure a built which should include your Utility.cs file. After that, try un-commenting and see what is reported.

Failing that… .zip up the project, if it’s under 10mb, and upload it on here and I will be happy to have a look.

Note : If you have any errors anywhere else, which would prevent a successful build (before the introduction of Layer) this could cause this.

1 Like

As soon as I comment out the first function everything goes red squiggly on me. I tried commenting out the whole thing and building the project and then uncommenting out but it gives me the same errors. Looking in the solution explorer it didn’t show my Utility script for some reason. So I deleted the script and then recreated it within VS2017. That did the trick!

Somewhat unrelated question but when working with VS do you tend to close it when going back and forth between Unity and VS? If I leave it open I typically get errors stating that my project has been edited outside of VS and asks if I should reload. I did reload once and it overwrote a bunch of code I created but when I hit ignore it seems to work better but I am unsure if I should really be ignoring the error?

1 Like

One of the things I was going to mention was whether the file was set to compile or not, but I don’t think that would have been the issue, I think you have actually described the issue yourself.

To answer your question, yes, I leave Visual Studio open, I have the full package and launching that every time would create so much waiting time I would never get anything done… lol…

So, what’s happening is that you have the project open in two places. Visual Studio is clever enough to note that something has changed, for example, when you have it open, flick back to Unity and add a new script. Instead of choosing “no”, choose “yes”, then your changes within Unity (in this case the addition of the new script) will be brought into Visual Studio.

I would put a very small amount of money on this is what happened. You added the script in Unity, had Visual Studio open, chose “no”, the project within Visual Studio then never saw the Utility.cs file and as such had no idea what Layer was.

If you want to be on the safe side, just make sure you have all of your files in Visual Studio saved before flicking back and forth and making more changes. I’ve not personally run into any problems like this.

Glad you have got it resolved anyway. If you’re really bored, you could probably try the steps above and see if a similar issue can be reproduced… I could then win that tiny amount of money :wink:

Privacy & Terms