Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Dissonance is not compatible with Unity Packages #196

Open
cliv3dev opened this issue May 29, 2020 · 10 comments
Open

[Feature] Dissonance is not compatible with Unity Packages #196

cliv3dev opened this issue May 29, 2020 · 10 comments

Comments

@cliv3dev
Copy link

cliv3dev commented May 29, 2020

Context

In my project I split my code between several Unity packages
image
Dissonance SDK is in one of those packages.

Expected Behavior

Dissonance should work as intended when embedded in a package.

Actual Behavior

When I open a project using those packages, I get this error:
image
image

Workaround

We updated DissonanceRoothPath.cs with this fix:
image

Steps to Reproduce

  1. put Dissonance SDK in a package
  2. Create a project and reference the package with dissonance

Your Environment

  • Dissonance version used: v6.4.6 (2020-03-11)

  • Unity version: 2019.3.11f1

  • Editor Operating System and version: Windows 10 Pro

Thanks!

@martindevans
Copy link
Member

Have you checked that the uses of the BasePath still work correctly after this change? e.g. Assets/Plugins/Dissonance/Core/Config/ChatRoomSettings.cs uses Resources.Load to load the path Path.Combine(DissonanceRootPath.BaseResourcePath, SettingsFileResourceName + ".asset"); - however from the documentation it looks like Resources.Load isn't intended to work with resources inside packages.

The Unity asset store team keep promising that the Unity Asset Store will support packages as a way to distribute assets. Once that's available we will definitely be moving over as soon as possible!

@cliv3dev
Copy link
Author

Hi Martin,
I finally had some time to propose a better solution. Here is my proposition change the file Startup.cs (see in attach). This solvves the warnings I have when using Dissonance as a package...
Startup.cs.zip
Tell me what you think...

@martindevans
Copy link
Member

Thanks for this! I'll see if I can include it in the next release.

@cliv3dev
Copy link
Author

cliv3dev commented Jul 1, 2020

Well, things are not over yet.
Now when I instanciate a DissoanceSetup prefab from MirrorDissonance integration, the MirrorIgnoranceCommsNetwork script doesn't seem to compil but I don't have any errors in the Unity Console:
image
And when starting the game I get this error:
image

I believe this comes from the fact that Dissonance is in a package... Do you see any workaround for this ?
thanks!

@martindevans
Copy link
Member

The most likely problem seems like something to do with assemblies (e.g. Mirror integration can't find some code it needs which is hidden away in the Dissonance assembly). I'm not sure precisely how asmdefs interact with packages. However I can't see how anything like that could lead to a situation where compile errors don't work properly!

@cliv3dev
Copy link
Author

cliv3dev commented Jul 1, 2020

Thanks for the hint Martin !
I think I nailed it: after upgrading to latest version of both Dissonance (v7.0.2) and DissonanceForMirror (v7.0.1), here are the changes I made:

  1. moved DissonanceVoip.asmdef file to Dissonance root directory
  2. As I have Mirror in another package, I added the Mirror package in the GUIDs list of DissonanceVoip.asmdef
  3. I created a MirrorIgnoranceEditor.asmdef in Integrations/MirrorIgnorance/Editor
  4. In MirrorIgnoranceEditor.asmdef, I flagged Editor as unique Platform,
  5. In MirrorIgnoranceEditor.asmdef, I added DissonanceVoip.asmdef, DissonanceVoipEditor.asmdef, and Mirror.asmdef in the Use GUIDs list.

And that's it! No more problems. Everything seems fine now!
dissonance can be put in a Unity package :)
cheers,

@JavelinIA
Copy link

@cliv3dev Did you change anything at the Startup.cs or DissonanceRoothPath.cs or did you fix it just by adding assembly definitions?

@cliv3dev
Copy link
Author

I had to do both: change the startup.cs + tweak assembly definition files to do the trick...

@JavelinIA
Copy link

Ouh, that was a quick reply. Thanks, i'll give it a try

@darrencperry
Copy link

darrencperry commented Jan 27, 2023

For me, the modifications to Startup.cs didn't work, so I added some code to search for the file in all asset paths and then I could find and set the install directory path successfully. We can probably replace the maybePathFile section with this but someone with more time on the project might have to make that call! You may have to commit the changed DissonanceRootPath.cs to your package though...

// search everywhere for DissonanceComms.cs
string foundPath = null;
var installDirectoryProjPath="";
var allAssetPaths = AssetDatabase.GetAllAssetPaths();
var fileName = "DissonanceComms.cs";
for(int i = 0; i < allAssetPaths.Length; ++i)
{
    if (allAssetPaths[i].EndsWith(fileName))
    {
        foundPath = allAssetPaths[i].Replace(Path.DirectorySeparatorChar.ToString(), "/").Replace("/DissonanceComms.cs", "");
    }
}

if (foundPath != null) {
    installDirectoryProjPath = foundPath;
}
else {

    //Find the DissonanceComms.cs file
    var maybePathFile = Directory
        .GetFiles(Application.dataPath, "DissonanceComms.cs", SearchOption.AllDirectories)
        .SingleOrDefault();
    if (maybePathFile == null)
    {
        Debug.LogError(
            "Cannot Find DissonanceComms.cs! Dissonance has not been installed correctly. Please delete all Dissonance related files and import them again");
        return false;
    }

    //Convert into a full path with normalized file separators
    var fileFullPath =
        new FileInfo(Path.GetFullPath(maybePathFile)).FullName.Replace(
            Path.DirectorySeparatorChar.ToString(), "/");
    if (!fileFullPath.StartsWith(Application.dataPath.Replace(Path.DirectorySeparatorChar.ToString(), "/")))
        throw new InvalidOperationException(
            "Dissonance install directory is not a child directory of 'Application.dataPath'!");
    
    //Work out the path to the install directory (as a project path)
    installDirectoryProjPath = Application.dataPath.Split('/').Last() + "/" + fileFullPath
        .Substring(Application.dataPath.Length).TrimStart('/').Replace("/DissonanceComms.cs", "");
    
    //If the path is correct we're good to go
    if (installDirectoryProjPath == DissonanceRootPath.BasePath)
        return true;
}

@martindevans martindevans removed their assignment Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants