Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Vector3 needs UnityEngine.Vector3 after transfering projet from 2017 to 2019

Discussion in 'Scripting' started by Zoro321, Apr 23, 2020.

  1. Zoro321

    Zoro321

    Joined:
    Nov 15, 2013
    Posts:
    13
    Hi,

    I have converted a project developed under Unity 2017.1 to 2019.3.10.

    After that, I get a HUGE quantity of compilation errors relating to Vector3, Vector2 and Vector4.

    Even if all scripts have a using UnityEngine directive, it does not find the Vector classes.

    If I do a find/replace from Vector3 to UnityEngine.Vector3, the errors disappear.

    The problem is that there are so many find/replace operations to conduct that I have been working on it for more than a week now and I am not done yet. :(

    I have googled around it and it seems I am the only person on the planet fighting with that problem.

    Also, I tried generating a blank Unity 2019 project and I have no problem using directly Vector3 instead of UnityEngine.Vector3. So it seems the problem come the way my project has been transferred.

    I wonder if there would be a config parameter to change in my project in order to fix it ?

    Thanks and please live in Unity :)


    Zoro321
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    Sounds like your project's dependencies got corrupted in some way. Try trashing the Library folder in your project folder and relaunching Unity. (It should be safe to delete that folder, but always good to make a backup before doing anything like that)
     
  3. Zoro321

    Zoro321

    Joined:
    Nov 15, 2013
    Posts:
    13
    Thank you StarManta.


    I did that, but the same problem is there after it rebuilt the Library folder.

    What puzzle me is that I do not have the problem for Quaternion or Transform, only for Vectors.
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    What's the exact error message (one of them)?
     
  5. Zoro321

    Zoro321

    Joined:
    Nov 15, 2013
    Posts:
    13
    Severity Code Description Project File Line Suppression State
    Error CS0029 Cannot implicitly convert type 'UnityEngine.Vector2' to 'Vector2' Assembly-CSharp ,,,


    I get similar errors with Vector3 and 4.

    If I change Vector3 definitiuon to UnityEngine.Vector3, the error message disappear.

    Problem is I have approximately 1 trillion of those replacements to do in the project.
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    I'm wondering if you somehow have classes named Vector2/3/4 in your project. Can you open in Visual Studio on one of the "wrong" ones and use "Go to definition..." on it? By "one of the wrong ones", I mean: you have Vector3 and UnityEngine.Vector3, so if you have a line of code like this:
    Code (csharp):
    1. Vector3 thisOneIsWrong = new UnityEngine.Vector3(0f,0f,0f);
    Select the Vector3 on the left and go to that definition. Then, select the Vector3 on the right and go to definition. My expectation would be that they'll go to two different places, and if the place one on the left takes you is within your project, then that's the problematic file and should probably be deleted.
     
  7. Zoro321

    Zoro321

    Joined:
    Nov 15, 2013
    Posts:
    13
    Damn, I found it !


    The people who wrote this system had the "SMART" idea (being sarcastic here) of redefining those classes as Serializable:



    #if !(UNITY_4_3 || UNITY_5 || UNITY_2017)
    [System.Serializable]
    public class Vector3 : System.Object
    {
    public float x;
    public float y;
    public float z;
    }
    [System.Serializable]
    public class Vector2 : System.Object
    {
    public float x;
    public float y;
    }
    #endif
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,517
    I'm not reading their minds, but I bet that they put those in because without them the serialization broke.. :)
     
  9. Zoro321

    Zoro321

    Joined:
    Nov 15, 2013
    Posts:
    13
    Thank you Starmanta !


    Are you working at Unity company or are you a developer which use Unity ?


    I feel sooo dumb for not having found it before !
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    Judging by that #IF define, I'm guessing this system was written in 2017. It specifically checks for Unity 4.3, 5.x, or 2017.x. It was probably meant to compensate for an old version of Unity where Vector2/3 weren't serializing? But then anyone using this code in 2018.x or beyond would have the issues you've had.

    Actually I don't see how it could have compiled even in Unity < 4.3 which it's clearly intended for, because without an implicit typecast operator from UnityEngine.Vector3 you'd still have the same compile issues...
     
    matkoniecz likes this.
  11. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    Just a dev who's been using Unity for 13 years :)
     
    matkoniecz likes this.