[Feature] Dissonance is not compatible with Unity Packages
Context
In my project I split my code between several Unity packages
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:

Workaround
We updated DissonanceRoothPath.cs with this fix:

Steps to Reproduce
- put Dissonance SDK in a package
- 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!
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!
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...
Thanks for this! I'll see if I can include it in the next release.
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:
And when starting the game I get this error:

I believe this comes from the fact that Dissonance is in a package... Do you see any workaround for this ? thanks!
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!
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:
- moved DissonanceVoip.asmdef file to Dissonance root directory
- As I have Mirror in another package, I added the Mirror package in the GUIDs list of DissonanceVoip.asmdef
- I created a MirrorIgnoranceEditor.asmdef in Integrations/MirrorIgnorance/Editor
- In MirrorIgnoranceEditor.asmdef, I flagged Editor as unique Platform,
- 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,
@cliv3dev Did you change anything at the Startup.cs or DissonanceRoothPath.cs or did you fix it just by adding assembly definitions?
I had to do both: change the startup.cs + tweak assembly definition files to do the trick...
Ouh, that was a quick reply. Thanks, i'll give it a try
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;
}