Search code examples
unity-game-enginegithubdll

Unity project breaks when pushed to and then cloned from GitHub


I have a Unity Project MainProject which I edited and then pushed to a branch in GitHub. I then merged this branch into my main branch. My friend wanted to edit and open the project so he cloned it but it did not open. I tried it too by cloning the main branch into a new directory on my computer. When I opened the newly cloned project ClonedProject, it would not open. Instead, Unity threw these errors:

ERROR: Assets/Scripts/scr_PlayerMovement.cs(4,7): error CS0246: The type or namespace name 'TMPro' could not be found (are you missing a using directive or an assembly reference?)

ERROR: Assets/Scripts/scr_PlayerMovement.cs(5,19): error CS0234: The type or namespace name 'UI' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)

I use VS Code for editing and my Unity version is 2023.2.20f1

I expected Unity to open my project like MainProject but it did not.

I searched the internet but none of the solutions had anything related to my specific problem. The weird thing is that Unity does generate a Library folder which should contain these things (I think).

Here is my .gitignore file because I am thinking that some files that Unity needs are not being pushed to the GitHub repository.: https://github.com/Sneezy123/ProjektKursInfo/blob/main/.gitignore (that's the project repo)

UPDATE:

What the answer metioned worked. The project can now be loaded. Still the the scripts are not applied to the objects and they have all there values to 0 / None. Which folder is missing in my repo.

That is fixed now too. I had to remove the *.meta which was in my .gitignore because of Visual Studio.


Solution

  • You need to push the Packages folder to the repository too, it seems that this folder has been ignored.

    # The packages folder can be ignored because of Package Restore
    **/[Pp]ackages/*
    

    I suggest you to use this .gitignore file: https://github.com/github/gitignore/blob/master/Unity.gitignore