Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question error CS0103: The name 'Unsafe' does not exist - Unsafe Code in Unity

Discussion in 'Scripting' started by wbonxx, Aug 22, 2020.

Thread Status:
Not open for further replies.
  1. wbonxx

    wbonxx

    Joined:
    Aug 22, 2020
    Posts:
    3
    Using Unity 2020.1
    OSX - Mojave
    VS 8.7
    All the rest is standard.

    I know this has been already discussed, but I could not solve the problem.

    I have some scripts that need unsafe code, but every time I end up migrating to a new system something goes wrong and I start getting this error:
    error CS0103: The name 'Unsafe' does not exist..

    Last time I solved doing a fresh project, since all the work around didn't work for me. But now I got sucked again and the project got too big to easily migrate.

    Already checked the "unsafe code" option in the player in unity.

    Also tried the solutions involving creating the files: smcs.rsp file to csc.rsp, or gmcs.rsp .
    It didn't work and I also don 't get why this should help.
    Deleting the library folder also didn't help.

    Someone could tell me how to solve the problem, possibly explaining how do things work?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,336
    Bunny83 likes this.
  3. wbonxx

    wbonxx

    Joined:
    Aug 22, 2020
    Posts:
    3
  4. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    687
    Only thing I can think of is that you need another assembly reference, even after checking the Unsafe Code box. But this is new to me.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,336
    That's not the keyword, that's the class. But sure, your point is taken.

    Unity's notion of
    unsafe
    has so many strings attached when I last looked at it in 2012 (Unity3.3) that I have completely avoided it, so mark this down to TIL. This may be one of those strings. Good luck!
     
  6. wbonxx

    wbonxx

    Joined:
    Aug 22, 2020
    Posts:
    3
    Could you elaborate? I still think it is odd that in Unity 2020 I'm still having this kind of problems.

    Guess is already there:
    using System.Runtime.CompilerServices;
     
  7. nukadelic

    nukadelic

    Joined:
    Aug 5, 2017
    Posts:
    73
  8. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,856
    nukadelic and MelvMay like this.
Thread Status:
Not open for further replies.