What does "Assertion failed on expression: 'prefab.IsPrefabParent()'" mean on my source data?
I'm sporadically getting the error message:
Assertion failed: Assertion failed on expression: 'prefab.IsPrefabParent()'
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
In my error log.
It hints that something might be wrong with some of my prefab data, but it doesn't indicate which files nor gives me information about what parameters trigger this assertion.
This function does not seem to be accessible from the public API so i have no documentation to fall back on.
Does anyone know what that function is evaluating so i can try and find the source data?
Answer by FantasyDR · Jul 19, 2018 at 12:23 PM
I've got the same issue after I tried to import some prefab files created by Unity 2018.2beta back into Unity 2018.1.2f1
It seems the serialization format has been changed since 2018.2, the 'serializedVersion' value is upgraded from 5 to 6 by 2018.2.
The 'm_IsPrefabParent' been renamed to 'm_IsPrefabAsset', and I guess this assersion is caused by missing value.
My solution is not very simple, which you could use as reference:
1st , force generate text format prefab in 2018.2 by changing Edit > Project Settings > Editor > SerializationMode to 'ForceText'
2nd, copy them to the 2018.1 project folder and downgrade content by replace 4 text strings:
"serializedVersion: 6" => "serializedVersion: 5"
"m_CorrespondingSourceObject" => "m_PrefabParentObject"
"m_IsPrefabAsset" => "m_IsPrefabParent"
"m_SourcePrefab" => "m_ParentPrefab"
2nd, copy them to the 2018.1 project folder and downgrade content by replace 4 text strings:
"serializedVersion: 6" => "serializedVersion: 5"
"m_CorrespondingSourceObject" => "m_PrefabParentObject"
"m_IsPrefabAsset" => "m_IsPrefabParent"
"m_SourcePrefab" => "m_ParentPrefab"
@FantasyDR Please explain this in better detail. In what file do we change those lines?
If you changed the Serialization$$anonymous$$ode to ForceText, all the prefab files are text based. You could open them by using any text editor (becareful do not modify the content by accident)
Replace those strings in your text based prefab files created by 2018.2.
You should do this in Unity 2018.2 env and do not forget to turn-off the 'ForceText' option and revert all changes.
I do not suggest any user to manually do this if you're not familar with Unity serialization or prefab data.
If you are using Windows and you don't want to do it manually and want this change to be applied to all of your prefab items, you can use this PowerShell command line, running it from your assets folder:
Get-ChildItem ./ *.prefab -recurse |
Foreach-Object {
$c = ($_ | Get-Content)
$c = $c -replace 'serializedVersion: 6','serializedVersion: 5'
$c = $c -replace 'm_CorrespondingSourceObject','m_PrefabParentObject'
$c = $c -replace 'm_IsPrefabAsset','m_IsPrefabParent'
$c = $c -replace 'm_SourcePrefab','m_ParentPrefab'
[IO.File]::WriteAllText($_.FullName, ($c -join "`r`n"))
}
I$$anonymous$$PORTANT NOTE: if you are using git with your project, be sure to NOT run this on the folder where your '.git' folder is since it could corrupt your git history;
Don't forget to add an empty line at the end or each time your will open/use it, Unity will add it and mess your git history
Get-ChildItem ./ *.prefab -recurse |
Foreach-Object {
$c = ($_ | Get-Content)
$c = $c -replace 'serializedVersion: 6','serializedVersion: 5'
$c = $c -replace 'm_CorrespondingSourceObject','m_PrefabParentObject'
$c = $c -replace 'm_IsPrefabAsset','m_IsPrefabParent'
$c = $c -replace 'm_SourcePrefab','m_ParentPrefab'
[IO.File]::WriteAllText($_.FullName, ($c -join "`r`n") + "`r`n")
}
Answer by gwendalbroudinpro · Oct 05, 2018 at 08:46 AM
If you are still having the error after having modifying each scenes/prefabs and it is occurring on 2018.2.x and 2018.1.x, it means you have broken prefabs links. Here is the ~~not so great~~ solution:
Go to your editor logs (see doc )
Search for
Assertion failed on expression: 'prefab.IsPrefabAsset()'
lines and look forOpening scene 'Assets/Scenes/MainHololens.unity'
who must be on top of it, that way you know at least which scene have broken prefabs linksOn your scene, click on the select button in the prefab instance's inspector
If it display
missing prefab
, you will have to recreate you prefabBy the way this error is not so harmless, you could lose a lot of work if you delete the scene containing the only instance of your prefab !!
Answer by TangledRealityStudios · Nov 23, 2018 at 06:17 AM
Mac version of script from CelitoOokaIsland and gwendalbroudinpro: find . -type f -name '*.prefab' -exec sed -i '' -e "s/serializedVersion: 6/serializedVersion: 5/g; s/m_CorrespondingSourceObject/m_CorrespondingSourceObject/g; s/m_IsPrefabAsset/m_IsPrefabParent/g; s/m_SourcePrefab/m_ParentPrefab/g" {} \;
Answer by Gui205 · Dec 12, 2018 at 03:12 AM
Really thank you !!!! You save my work !
PS : that's work also for Unity 2018.2+ to Unity 2017.1+