Search Unity

Bug Merging Two Projects Together

Discussion in 'Editor & General Support' started by MIdrees, May 20, 2021.

  1. MIdrees

    MIdrees

    Joined:
    May 17, 2021
    Posts:
    4
    Hi,
    I will try my best to explain this problem.

    Actually I have two different projects let's say A and B.

    A and B Has some common assets that they are using which are imported from asset store. Both projects have the same folder structure.

    In project B I have changed 2 scripts from one of the common assets.
    ( By changing I mean I renamed the scripts to different ones and added a namespace to avoid conflicts )

    Ok So Before integrating both projects together they are working totally fine.
    Now when I integrate the B project with A ( I tried two methods for integration. First one to copy the Asset folder of B project in A and the other one is to Export the B project as package and import it in the A project. ).
    Remember the 2 scripts that I changed before integration ?.

    These 2 scripts were attacked to a GameObject in a Scene. When I open that Scene after integration and look for these 2 scripts they are just changed to the default ones.
    By default ones I mean the GameObject get's the original script references which I just changed before.

    Let me provide some pictures to understand this a bit more.

    I will really appreciate your Time and help. Thanks
     

    Attached Files:

    Last edited: May 20, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    Unity doesn't "know" scripts by their names. They only know it by the GUID assigned in the .meta file associated with the script.

    In order for the common scripts you list above to work, those scripts must use the same GUID in both projects.

    To successfully implement a "Project Chimera" where you pull off what you contemplate above, you should first fork both projects, then do GUID search/replace to bring the shared scripts perfectly into alignment GUID-wise.

    I've done this many times and it is awesome. There is no easier engine than Unity when you want to mash up two random projects. Once you understand the whole GUID thing above, you'll go "AHA!" and be a master at it. Here is some more specific info:

    Some info about Missing script warnings, GUIDs, renaming GUIDs, etc:

    https://forum.unity.com/threads/problem-with-git-and-missing-scripts.1090876/#post-7024801
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6487297
    https://forum.unity.com/threads/scr...ead-after-loading-editor.998413/#post-6488230

    Also, use source control to help you iterate through it all and get it right.
     
    JoNax97 and Joe-Censored like this.
  3. MIdrees

    MIdrees

    Joined:
    May 17, 2021
    Posts:
    4
    Thanks for your help.

    Instead of renaming I created new scripts and copied and past the code from the custom ones.
    This solved the issue because now both scripts have different meta ID's now.

    For those who want to make their own custom scripts from other assets.
    Then duplicate them instead of renaming them.

    Thanks for your help again @Kurt-Dekker.
     
    Kurt-Dekker likes this.
  4. MIdrees

    MIdrees

    Joined:
    May 17, 2021
    Posts:
    4
    Hey @Kurt-Dekker If I import new asset from asset Store does the unity creates new meta files for all the asset files ?
    Or unity just take the files that comes with the package ?
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,735
    I'm pretty sure it is this. The reason is that if you reimport the same asset at a newer version, Unity is able to relink and selectively replace the previous files. I still like to completely DELETE old assets, then import the new ones, since this takes care of files that were removed in the new distribution.
     
  6. MIdrees

    MIdrees

    Joined:
    May 17, 2021
    Posts:
    4
    @Kurt-Dekker You are correct that's how unity works with files.
    Unity creates a Unique GUID for each file and folder which will be used forever in the future updates.
    When Importing assets from asset store the Unity keeps the original Meta files that comes with the asset.

    You can test it by deleting the asset from the project and reimport back from the asset store.
    Your game will work as before without any reference errors.

    Thanks Again.