Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Problem with Git and missing scripts

Discussion in 'Editor & General Support' started by gennen, Apr 10, 2021.

  1. gennen

    gennen

    Joined:
    Feb 5, 2013
    Posts:
    18
    I hope this is the right place to be posting this - apologies if not.

    I'm using Git to manage a project and have run into a bizarre issue that I'm out of ideas on how to solve. I have a scene which contains a prefab which has a component. At one point due to version control shennanigans I had to locally delete the .cs that the component is based on and recreate it. Locally, all of this is working fine. For any other machine that pulls the repository, the prefab shows the 'missing script' error for that component. I have dirtied and resubmitted the scene, prefab, script, and script metadata, but no luck. If anyone has any thoughts on what the problem could be or how to resolve it I would really appreciate
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,033
    If you delete a script and recreate it, Unity will produce a new .meta file, with a randomly chosen
    guid
    .

    The
    guid
    inside that metafile is what "connects" the script to the prefabs / scenes / assets.

    Here's an example, with the
    guid
    fortuitously underlined with a red squiggle:

    Screen Shot 2021-04-10 at 9.13.40 AM.png

    What you need to do is look in git history and find out what the original
    guid
    was for that file (the one you deleted when you deleted the script), then modify the current metafile for your new script to be the same.

    You can modify meta files with any text editor. Don't damage any whitespace obviously.

    This also presupposes that you named all your public variables identically.
     
    Ben_at_Work and gennen like this.
  3. gennen

    gennen

    Joined:
    Feb 5, 2013
    Posts:
    18
    You are an absolute hero.
     
    Last edited: Apr 10, 2021
    Kurt-Dekker likes this.