• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by rl_is · May 21, 2013 at 08:31 AM · refreshmetafilesguidregenerate

Forcing a GUID to regenerate/refresh

Hi all,

Basically I'm in a situation where I have several projects which need to be merged into one, and the problem I have is that they share GUIDs between objects that are in fact unique to each project.

This is because when created, each project was copied from the last (along with the meta files), and then all the assets were then manipulated to suit that project.

I realise this pretty much goes against the whole purpose of GUIDs, but is there any way to force a GUID to be regenerated for a file while maintaining references to it? Even if I had to write a script that skimmed each scene file and manipulated the asset database I'd still be willing to try it.

Thanks in advance

Comment
Yulorda

People who like this

1 Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TonyLi · May 21, 2013 at 06:17 PM 1
Share

Have you tried to export each project as a package and then re-import them into the master project?

avatar image rl_is · May 21, 2013 at 11:19 PM 0
Share

Thanks Tony - that's looking like the easiest option at the moment, although I haven't tried it yet. Looking at the scenes in each project, I'm finding that I may be able to (via an editor script) break all prefab bindings and replacing some of the other shared assets by duplicating and relinking them through SerializedObjects. Ultimately though, I think I'll try packaging if that gets too complex (which it probably will) :)

avatar image ricardo_arango ♦♦ · May 21, 2013 at 11:32 PM 0
Share

Exporting packages should work. That how the AssetStore can provide packages.

Alternatively you could set the Editor to use .meta files and modify the GUIDs. But, this is very hacky and you are on your own pretty much if you go that route.

avatar image mposwal · Mar 26, 2014 at 07:06 PM 0
Share

I am in the exact same situation with merging two projects. Making packages as Tony_Li suggested did not work for me.

I tried going into my two similar projects, moving scripts into namespaces and making subdirectories for all assets (for example, Scripts/Project1/... and Scripts/Project2/... ) and then exporting everything from the two projects and reimporting them into a single project, however, when I imported the second project I guess they still shared GUIDs because Unity overwrote all of the assets from the first project with those from the second.

The only way I found to make unity regenerate the GUIDs was to copy the second project's folders into the first. However, since things like prefabs keep track of their connections through the GUIDs all of my prefabs from the second project were referencing assets from the first instead of the proper ones that just had their GUIDs refreshed, so that's not really a solution for me.

Any help would be appreciated!

avatar image Bunny83 · Mar 26, 2014 at 07:14 PM 0
Share

@mposwal: I don't think there's a real solution to that problem. As you said yourself the GUID is the thing that glues everything together. Since Unity doesn't have a built-in way for creating a new GUID for an asset it's getting tricky...

Like ricardo_arango said you might be able to change the GUID in the metafile, but haven't tested this yet. In any way you should first backup both projects ;)

edit
if you have unity pro you can try to manually generate a new guid for an asset and replace this guid in all meta files / assets. Note: This probably only work with Unity pro where you can set the asset-serialization to force-text which isn't available in the free version.

When set to force-text all asset files (prefabs, scenes, ...) are saved in Yaml and will contain the guid in plain text.

5 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by rl_is · May 22, 2013 at 01:31 AM

Ok thanks to TonyLi and ricardo_arango it looks like packages are my best bet. In my head I was confusing packages with bundles, but they are indeed the best option here. Thanks!

Comment
NVJOB
havokentity

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by ZimM · Sep 02, 2014 at 12:45 PM

Just faced the same problem and wrote my own tool to regenerate the GUIDs. It works from Unity Editor itself and replaces all GUIDs to random ones. It also takes care of not replacing GUIDs for built-in resources. I does not requires any additional files, so it is pretty much a one click tool. To use it, call "Tools/Regenerate asset GUIDs" menu item. Of course, it requires Asset Serialization to be set to Force Text. Hopefully this'll come in use for somebody.

[1]: /storage/temp/31901-unityguidregenerator.zip


unityguidregenerator.zip (2.0 kB)
Comment
allenwp
Jason-RT-Bond
NVJOB
AlexTerekhovTDS
viesc123
BelyakovM

People who like this

6 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image VIC20 · Jan 15, 2016 at 02:28 PM 0
Share

Thank you!

avatar image allenwp · Aug 30, 2017 at 02:11 PM 1
Share

Thanks! This script works great, straight out of the box.

I used this to help me update from a 3 year old version of TextMesh Pro to the latest version -- I wanted to have both the old and new TextMesh Pro usable in my project, so I could maintain the old TextMeshes while replacing them with new TextMeshes.

This meant I needed to change all the GUIDs of the assets inside a specific folder. To do this, I just changed the "guidOldToNewMap.Add(oldGuid, newGuid);" bit to the following:

 if (filePath.StartsWith("[The path to the folder I care about]"))
 {
     string newGuid = Guid.NewGuid().ToString("N");
     guidOldToNewMap.Add(oldGuid, newGuid);
 }
 else
 {
     guidOldToNewMap.Add(oldGuid, oldGuid);
 }

Worked like a charm! Thanks again!

avatar image

Answer by mposwal · Mar 28, 2014 at 08:06 PM

I followed the method Bunny83 recommended in the comments and wrote this C# program that will go through and regenerate all the GUID's in a project and I successfully got it to work! (note, this is not a Unity script. I built and ran it through monodevelop on its own. I predict bad things might happen if you tried to modify the GUIDs while Unity is open and running)

Prerequisites:

  1. Unity Pro is required, since this will only work if you set Asset Serialization to Force-Text and use visible .meta files.

  2. Make sure there aren't any folders with spaces in the name (such as Assets/Standard Assets/... you'll have to replace the spaces with underscores or something). Filenames with spaces in them are OK.

  3. I used grep and sort -u to get a list of all the GUIDs in my project. DO NOT mess with GUIDs that look like "0000000000000000e000000000000000" (the 17th character might be anything from 1-f). These do not refer to files in your project. It appears they refer to built-in unity assets or something like that.

  4. BACK UP YOUR PROJECT

  5. Be sure to delete the "Library" folder in your project before running

  6. You might also want to close Unity before running this

using System; using System.IO; using System.Collections.Generic;

 namespace UnityGUIDReplacer
 {
     class MainClass
     {    
         public static void Main (string[] args)
         {
             MainClass m = new MainClass();
             m.replaceGUID();
             
         }
         
         public void replaceGUID() {
             //path to list of old GUIDs
             string oldGUIDsPath = "/GUIDsUniq.txt";
             //path to list of new GUIDs. You can generate them easily with System.Guid.NewGuid().ToString("N")
             string newGUIDsPath = "/newGUIDs.txt";
             //path to the list of files in which we want to alter GUIDs. These include all .meta, .mat, .prefab, and .unity files
             string fileListPath = "/listOfFiles.txt";
             //path to project
             string pathPrefix = "/Users/.../UnityProjectFolder";
             
             
             //build a dictionary out of the GUIDs
             string[] oldGUIDsList = File.ReadAllLines(pathPrefix + oldGUIDsPath);
             string[] newGUIDsList = File.ReadAllLines(pathPrefix + newGUIDsPath);
             Dictionary<string, string> GUIDDict = new Dictionary<string, string>();
             
             for(int i = 0; i < oldGUIDsList.Length; i++) {
                 GUIDDict.Add(oldGUIDsList[i], newGUIDsList[i]);
             }
             //Get the list of files to modify
             string[] fileList = File.ReadAllLines(pathPrefix + fileListPath);
             foreach (string f in fileList) {
                 string[] fileLines = File.ReadAllLines(pathPrefix + f);
                 
                 for(int i = 0; i < fileLines.Length; i++) {
                     //find all instances of the string "guid: " and grab the next 32 characters as the old GUID
                     if(fileLines[i].Contains("guid: ")) {
                         int index = fileLines[i].IndexOf("guid: ") + 6;
                         string oldGUID = fileLines[i].Substring(index, 32); 
                         //use that as a key to the dictionary and find the value
                         //replace those 32 characters with the new GUID value
                         if(GUIDDict.ContainsKey(oldGUID)) {
                             fileLines[i] = fileLines[i].Replace(oldGUID, GUIDDict[oldGUID]);
                             Console.WriteLine("replaced \"" + oldGUID + "\" with \"" + GUIDDict[oldGUID] + "\" in file " + f);
                         }
                         else Console.WriteLine("GUIDDict did not contain the key " + oldGUID);
                     }
                 }
                 //Write the lines back to the file
                 File.WriteAllLines(pathPrefix + f, fileLines);
             }
         }
     }
 }

After running, open Unity back up and it will reimport all of your assets. If everything worked properly, there shouldn't be any broken prefabs and there won't be any clashes between GUIDs from different projects that you are trying to merge. I ran it on a project with about 2000 files and it finished in a couple of minutes. Hopefully this is useful for somebody!

Comment
Bunny83
Yulorda

People who like this

2 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by lunaduclos · Jan 01, 2019 at 03:29 PM

I've done some additional modifications to the tool written by @ZimM to make it more generally useful.

It'll now prompt for the folder or file with assets you want to regenerate, print out new guids in the logs, and prompt you before finally applying those modifications along with the number of files that will be regenerated.


unityguidregenerator.txt (8.8 kB)
Comment
Yulorda
JVimes

People who like this

2 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hinne123 · Feb 27, 2022 at 04:16 PM 1
Share

Sounds fantastic! I am somehow not able to download your file, it just By the way, why is it a .txt file, i would have expected a .unitypackage. Is there a possiblity to download your package somewhere else? Thanks in advance

avatar image JVimes · Oct 16, 2022 at 01:39 AM 0
Share

Downloads seem broken on this page, but I think I got it working by removing the file extension from the download URL (try: unityguidregenerator) then adding the file extension back after download. Same for the original, unityguidregenerator.zip, above.

avatar image

Answer by gbabic · May 26, 2016 at 01:02 PM

Hi Fellows,

Here is another submission for a workaround. It's for *nix and Mac only though (unless you have cygwin on Windows).

You can find, replace, or generate randomGUIDs in your project.

Recommended usage is:

  1. Generate random (./guid.sh random)

  2. Verify it's unique with find (./guid.sh find YOUR_NEW_RANDOM_GUID"

  3. Replace existing GUID with newly generated random GUID (./guid.sh replace YOUR_CURRENT_GUID YOUR_NEW_RANDOM_GUID)

Like all the others here you need force text serialisation on your project and visible meta files.

Contents of guid.sh:

 #!/bin/bash
 
 find(){
     if [ -z "$1" ]; then
                 help
                 exit 1;
         fi
 
     echo "Searching for GUID references..."
     numFound=$(grep -rl $1 Assets | wc -l)
     if [ $numFound -gt 0 ]; then
         echo "Found $numFound matches for that GUID"
     else
         echo "GUID not found"
     fi
 }
 
 replace(){
     if [ -z "$1" ]; then
         help
         exit 1;
     fi
 
     if [ -z "$2" ]; then
         help
                 exit 1;
         fi
 
     current=$1
     new=$2
     grep -rl --null $1 Assets | xargs -0 sed -i '' "s/$current/$new/g"
 
     if [ $? -ne 0 ]; then
         echo "There was a problem, consider rolling back."
     else
         echo "Your GUID has been replaced, restart Unity."
     fi
 }
 
 random(){
     # we sleep here because we can only use seconds on mac
     # this helps keep it unique
     sleep 1
     echo $(md5 -qs "$(date +%s)")
 }
 
 # usage information
 help(){
     echo "GUID helper"
     echo "This script can help find and replace GUIDs"
     echo "as well as generate a random GUID"
     echo
     echo "WARNING: this can really mess with your project"
     echo "make sure you have a backup"
     echo "Before running replace make sure your new guid"
     echo "does not already exist with the find funciton."
     echo "Make sure that this script is run from the"
     echo "project root!"
     echo
     echo "Functions: find, replace, random"
     echo "Usage of find: ./guid.sh find YOUR_GUID"
     echo "Usage of replace: ./guid.sh replace YOUR_CURRENT_GUID YOUR_NEW_GUID"
     echo "Usage of random: ./guid.sh random"
 
 }
 
 # if no arguments passed then show help
 if [ ! $1 ]; then
         help
         exit 1
 fi
 
 # call arguments verbatim
 $@

Just put that in a file named guid.sh in your project root and march it as executable with

 chmod +x guid.sh

Hope this helps someone.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Project automatically reimports, changing GUIDs in the meta files. 0 Answers

Handles.DrawLine refresh rate in scene view 1 Answer

5.4 Console Window Won't Automatically Update With Logs/Errors 0 Answers

Health Regeneration 2 Answers

Argument Exception - same key 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges