Combine four Unity projects into one dealing with duplicate scripts

1.5k views Asked by At

I've recently been given a Unity VR project to tidy up. Very messy, wasn't even on Git. It consists of four Unity scenes, but each one lives in it's own Unity project. I need to have all of them in one project for the build, which is where the current problem lies. The scenes have a lot of scripts in common which were copy pasted between the projects. Some of these are absolutely identical, others have one or two lines difference.

From my research namespaces seemed the best way forward, so that I don't have to go and tweak everything manually. I gave the base scene a unique namespace, worked fine. I imported a second scene as a package and gave it a different namespace.

Now I get a bunch of compile errors to do with the VR scripts from Valve Corporation, e.g.

Partial declarations of 'SteamVR_Behaviour_BooleanEvent' must not specify different base classes

Duplicate 'Serializable' attribute

The namespace 'Valve.VR' already contains a definition for 'SteamVR_Behaviour_BooleanEvent'

I don't understand these scripts and don't want to (and shouldn't need to) mess with them.

An example of what causes the last error is having:

  /// <summary>This event fires whenever a change happens in the action</summary>
        public SteamVR_Behaviour_BooleanEvent onChange;

    /// <summary>This event fires whenever the action is updated</summary>
    public SteamVR_Behaviour_BooleanEvent onUpdate;

    /// <summary>This event will fire whenever the boolean action is true and gets updated</summary>
    public SteamVR_Behaviour_BooleanEvent onPress;

And then this further down in the script (SteamVR_Behaviour_Boolean.cs):

[Serializable]
    public class SteamVR_Behaviour_BooleanEvent : UnityEvent<SteamVR_Action_Boolean> { }

Each BooleanEvent gets highlighted.

Am I missing something in my namespace procedure or does anyone know a more efficient way of resolving my issue? I've spent days with this already so any advice would be greatly appreciated.

1

There are 1 answers

0
onemorecoder On

What I ended up doing was this: (I cut corners a lot this way and honestly didn't think it would work, but it did somehow.)

-Selected base scene.

-Imported next scene as a package, upon import deselected scripts that showed up with the little gray symbol for being potential duplicates.

-Deleted any duplicate scripts or folders of scripts that were causing errors and didn't automatically get picked up as duplicates when importing.

-Refactored the namespace for the scripts from the imported scene. The Rider IDE has a great way of dealing with this, highly recommend getting the evaluation license just for this feature. This tutorial steps through the namespace refactoring https://www.youtube.com/watch?v=vLrGdx-Ob3g just make sure to switch your IDE inside Unity from Edit > Preferences > External Tools > External Script Editor. Otherwise Rider won't link up to Unity and you won't be able to refactor.