Problem with Git and missing scripts

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

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:

7024801--832060--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.

2 Likes

You are an absolute hero.

1 Like