... okay, It seems that just adding that one line doesn't handle SwitchStateGroups, StateGroups and the Switches/States within them. So my version 2.0 looks like this (again, my addition is marked with green):
foreach (var pair in _WwiseObjectsToAdd)
{
//Add objects
var type = pair.Key;
foreach (var info in pair.Value)
{
WwiseObjectReference referenceObject = WwiseObjectReference.FindOrCreateWwiseObject(type, info.Name, info.Guid);
//Handle the case of referenceObject being a StateGroup
if (type == WwiseObjectType.StateGroup)
{
WwiseStateGroupReference stateGroupReferenceObject = referenceObject as WwiseStateGroupReference;
var groupValue = info as AkWwiseProjectData.GroupValue;
if (groupValue != null)
{
foreach (var value in groupValue.values)
{
WwiseStateReference stateReferenceObject = WwiseObjectReference.FindOrCreateWwiseObject(WwiseObjectType.State, value.Name, value.Guid) as WwiseStateReference;
stateReferenceObject.GroupObjectReference = stateGroupReferenceObject;
}
}
}
//Handle the case of referenceObject being a SwitchGroup
else if (type == WwiseObjectType.SwitchGroup)
{
WwiseSwitchGroupReference switchGroupReferenceObject = referenceObject as WwiseSwitchGroupReference;
var groupValue = info as AkWwiseProjectData.GroupValue;
if (groupValue != null)
{
foreach (var value in groupValue.values)
{
WwiseSwitchReference switchReferenceObject = WwiseObjectReference.FindOrCreateWwiseObject(WwiseObjectType.Switch, value.Name, value.Guid) as WwiseSwitchReference;
switchReferenceObject.GroupObjectReference = switchGroupReferenceObject;
}
}
}
}
System.Collections.Generic.List<AkWwiseProjectData.AkBaseInformation> removeList = null;
if (!_WwiseObjectsToRemove.TryGetValue(pair.Key, out removeList))
continue;
removeList.Sort(AkWwiseProjectData.AkBaseInformation.CompareByGuid);
foreach (var info in pair.Value)
{
var index = removeList.BinarySearch(info, AkWwiseProjectData.AkBaseInformation.CompareByGuid);
if (index >= 0)
removeList.RemoveAt(index);
}
}
However, this has made me notice another bug (?) – namely that if you delete a State or Switch within a group, its object reference asset will not be deleted in Unity.
If you delete the whole group, the States/Switches within will be deleted, except from any States or Switches that you deleted directly – they become somehow untracked and will exist forever (if you don't delete them manually).
Best, Jakob