Skip to content

Commit

Permalink
Merge pull request #10 from VRLabs/fix/fix-crashing
Browse files Browse the repository at this point in the history
Fix crashing when instancing a package with a prefab which references an FBX
  • Loading branch information
jellejurre authored Sep 21, 2024
2 parents 2bbd0b9 + 8c97153 commit 0a2b77c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Instancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ static void FixReferences(string[] localAssetPaths, string sourceFolder, string
bool newChanged = false;
do
{
if (property.propertyPath.Contains("m_Modification")) continue;
if (property.propertyType == SerializedPropertyType.ObjectReference)
{
if (property.objectReferenceValue != null)
Expand Down Expand Up @@ -297,24 +298,14 @@ static void RenameInstance(string[] localAssetPaths, string targetFolder, string
UnityEngine.Object[] targetAssets = AssetDatabase.LoadAllAssetsAtPath(targetAssetPath).Where(x => x != null).ToArray();
if (targetAssets.Length == 0) continue;
string[] possibleNames = new []{packageName, packageName.Replace("-", ""), packageName.Replace("-", " ")};

String fileName = Path.GetFileName(targetAssetPath);
foreach (string possibleName in possibleNames)
{
if (fileName.StartsWith(possibleName))
{
fileName = ReplaceAtStart(fileName, possibleName, newInstanceName);
AssetDatabase.RenameAsset(targetAssetPath, fileName);
break;
}
}

foreach (var targetAsset in targetAssets)
{
SerializedObject serializedObject = new SerializedObject(targetAsset);
SerializedProperty property = serializedObject.GetIterator();
do
{
if (property.propertyPath.Contains("m_Modification")) continue;
if (property.propertyType == SerializedPropertyType.String)
{
string value = property.stringValue;
Expand All @@ -333,6 +324,17 @@ static void RenameInstance(string[] localAssetPaths, string targetFolder, string

serializedObject.ApplyModifiedProperties();
}

String fileName = Path.GetFileName(targetAssetPath);
foreach (string possibleName in possibleNames)
{
if (fileName.StartsWith(possibleName))
{
fileName = ReplaceAtStart(fileName, possibleName, newInstanceName);
AssetDatabase.RenameAsset(targetAssetPath, fileName);
break;
}
}
}
}

Expand Down

0 comments on commit 0a2b77c

Please sign in to comment.