Giter Site home page Giter Site logo

unity-guid-regenerator's Introduction

๐Ÿ†” Unity GUID Regenerator

License: MIT No Maintenance Intended

A Unity editor tool to regenerate GUID for your assets

โš ๏ธ Disclaimer: Only use this if needed. Intentionally modifying the GUID of an asset is not recommended unless certain files are problematic

What is GUID in Unity?

GUID is a unique hash that is automatically generated and assigned when creating a new asset. This GUID is used when a serialized asset references another asset.

GUID

It is stored in an asset's meta file. Manually you can open and view a meta file in a text editor to get the GUID. However, Unity has its AssetDatabase API that is useful for accessing and performing operations on assets.

Why regenerate a GUID?

When you work on multiple projects that are based on existing projects, chances are most of the assets have the same GUID. This can cause some issues later on when you add more assets from existing projects. Unity won't be able to distinguish the difference between assets with same GUID even they have different file name and contents. This can cause Unity to associate references to the wrong asset.

The simplest workaround for this is to duplicate the asset. The newly created asset will have its own GUID assigned by Unity. However, you will need to manually replace all its references in the Scene, prefabs, etc.

Installation

  1. Unity Editor > Windows > Package Manager
  2. Add package from git URL...
  3. Enter https://github.com/jeffjadulco/unity-guid-regenerator.git

Usage

inst

  1. Select one or multiple assets (folders are not supported)
  2. Right click > Generate GUID
  3. A modal will show to warn and confirm the action. Click Proceed.
  4. Wait for the operation to complete. Note that this will take a long time on larger projects.
  5. A report will be logged in the console detailling what assets are updated/skipped.

Notes

  • Scenes are always skipped as this corrupts the scene.

Author

License

This project is open source and available under the MIT License.

unity-guid-regenerator's People

Contributors

jeffjadulco avatar mayo-nesso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

unity-guid-regenerator's Issues

Folders` GUIDs regeneration.

First of all, many thanks for this tool!!!

I had some problems with GUIDs that's why I found this repo. And in my situation, it was needed to also regenerate folders` GUIDs.
Maybe I'm missing something, but it doesn't have much sense to implicitly exclude folders from GUIDs regeneration process.
(AssetGUIDRegenerator.cs, line 137)

// Skip folders
if (IsDirectory(assetPath)) continue;

Maybe it would be better to remove this line. Or to make a setting to enable/disable this behavior.

Cheers!

Not quite working? Can't install to Unity...

Unity version 2019.4.18f1 Personal
Win10 Home

Package manager tab, then + Add Package from URL, Paste: https://github.com/jeffjadulco/unity-guid-regenerator/releases/tag/1.0.1

Error Adding Package, UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Download to local hard drive, then Package manager tab + Add Package from Disk (the program seems to be looking for .json files...) If I force [email protected], it just fails.

Am I doing this right? I'm trying to follow the instructions on the readme.md, but there appears to be something missing.. Many thanks.

Material GUID references on fbx files are not replaced

Scenario:

  1. Given that you have a FBX file with a material mapped to it (*)
  2. When you regenerate the material GUID file
  3. Then the FBX loses the reference to it

(*) Tested with FBX using legacy standard material creation mode and embedded materials

This appears to happen because the reference to the material is in the FBX meta file and not the asset file. FBX meta file ex::

fileFormatVersion: 2
guid: 3ea85db3da6e4524cb0ff3011bcbaff7
ModelImporter:
  serializedVersion: 21
  internalIDToNameTable: []
  externalObjects:
  - first:
      type: UnityEngine:Material
      assembly: UnityEngine.CoreModule
      name: Howl_M
    second: {fileID: 2100000, guid: 253e123fd6b1fe74a8dfddc60c2a7073, type: 2} // <- here is the material GUID inside FBX meta
  materials:
    materialImportMode: 1
(...)

Ability to duplicate folder but with new guid

Created code for that and extending from outside the code (static)
Wanted to contribute and open PR but I see there ois no code in the repo, attach it here
@jeffjadulco

public class DuplicateAndRegenerateGUIDFolder
    {
        [MenuItem("Assets/Regenerate GUID/ Duplicate and Regenerate GUID for Folder")]
        public static void CopyRegenerateAndPasteFolder()
        {
            var selectedGUIDs = Selection.assetGUIDs;

            if (selectedGUIDs.Length == 0 || !AssetGUIDRegeneratorMenu.RegenerateGUID_Validation())
            {
                Debug.LogWarning("No valid folder selected.");
                return;
            }

            var selectedPath = AssetDatabase.GUIDToAssetPath(selectedGUIDs[0]);
            if (!File.GetAttributes(selectedPath).HasFlag(FileAttributes.Directory))
            {
                Debug.LogWarning("Selected asset is not a folder.");
                return;
            }

            var folderTempPath = Path.Combine(Application.temporaryCachePath, Path.GetFileName(selectedPath));

            var newFolderName = Path.GetFileName(folderTempPath) + "_Copy";

            if (Directory.Exists(newFolderName) || Directory.Exists(folderTempPath))
            {
                Debug.LogWarning($"A folder with name {newFolderName} already exists in the destination.");
                DeleteTempFolder(folderTempPath);
                return;
            }

            CopyDirectory(selectedPath, folderTempPath);

            AssetGUIDRegeneratorMenu.RegenerateGUIDWithFolders_Implementation();

            var parentDirectory = Directory.GetParent(selectedPath).FullName;
            PasteFolder(folderTempPath, parentDirectory);

            DeleteTempFolder(folderTempPath);
        }

        private static void DeleteTempFolder(string folderCopyPath)
        {
            if (Directory.Exists(folderCopyPath))
            {
                Directory.Delete(folderCopyPath, true);
            }
        }

        private static void CopyDirectory(string sourceDir, string destinationDir)
        {
            Directory.CreateDirectory(destinationDir);
            foreach (var file in Directory.GetFiles(sourceDir))
            {
                var dest = Path.Combine(destinationDir, Path.GetFileName(file));
                File.Copy(file, dest);
            }

            foreach (var dir in Directory.GetDirectories(sourceDir))
            {
                var dest = Path.Combine(destinationDir, Path.GetFileName(dir));
                CopyDirectory(dir, dest);
            }
        }

        private static void PasteFolder(string sourceDir, string destinationParent)
        {
            var newFolderName = Path.GetFileName(sourceDir) + "_Copy";
            var newFolderPath = Path.Combine(destinationParent, newFolderName);

            if (Directory.Exists(newFolderPath))
            {
                Debug.LogWarning($"A folder with name {newFolderName} already exists in the destination.");
                return;
            }

            CopyDirectory(sourceDir, newFolderPath);
            AssetDatabase.Refresh();
        }
    }

Skipping Scene files does not seem necessary

AssetGUIDRegeneratorMenu.cs Implements a check for unity scene files at line 204. I removed this since I needed the GUID of a scene regenerated and it worked just fine. My version control also indicates that the scene file was the only file to be modified, so from what I can tell it works just fine

Folder Support

It would be really nice to have folder support so we can just click on the folder containing the assets we want to update. I implemented a little hack with AssetDatabase.FindAssets. It caused it to fall into an endless loop, but when using the Task Manager and ending the Unity Task, I was happy to find that the guids were updated :).

TL; DR;

Feature request for folder support.

Edit: Typo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.