Thursday, January 24, 2019

Backporting Unity 2018.2 to Unity 2018.1

First off, I don't recommend back porting Unity projects as it usually never ends well.  Your best bet is to revert your repository to a date prior to updating Unity.  That said, sometimes it is unavoidable.  In our case, we updated to Unity 2018.2 awhile back for a Hololens project.  Then we were asked to port the Hololens application to Magic Leap which currently is only supported in a technical preview on 2018.1.  We've done too much development on 2018.2 for reverting to make sense so here we are.


Step 1:
Close Unity and delete the Library folder within your project as well as any build folders and other temporary folders.  The Library folder is important as you may experience the editor crashing while trying to run a project in 2018.1 with cached properties from 2018.2.  The build folders were throwing some access denied errors for me but that may be specific to UWP and probably not as important for most projects.

Step 2.
Open the power shell and navigate to your project folder. Enter in each of these four commands 1 at a time.  Note, these are compiled from a few stackoverflow answers which I am having trouble finding at the moment to link credit to.


$configFiles = Get-ChildItem . *.prefab -rec
 foreach ($file in $configFiles)
 {
     (Get-Content $file.PSPath) |
     Foreach-Object { $_ -replace "m_IsPrefabAsset", "m_IsPrefabParent" } |
     Set-Content $file.PSPath
 }


 $configFiles = Get-ChildItem . *.unity -rec
 foreach ($file in $configFiles)
 {
     (Get-Content $file.PSPath) |
     Foreach-Object { $_ -replace "m_IsPrefabAsset", "m_IsPrefabParent" } |
     Set-Content $file.PSPath
 }


 $configFiles = Get-ChildItem . *.unity -rec
 foreach ($file in $configFiles)
 {
     (Get-Content $file.PSPath) |
     Foreach-Object { $_ -replace "m_SourcePrefab", "m_ParentPrefab" } |
     Set-Content $file.PSPath
 }


I did not find any references to this last one online, but I ran into some issues with prefabs within the scene losing reference and this fixed it.

 $configFiles = Get-ChildItem . *.unity -rec
 foreach ($file in $configFiles)
 {
     (Get-Content $file.PSPath) |
     Foreach-Object { $_ -replace "m_CorrespondingSourceObject", "m_PrefabParentObject" } |
     Set-Content $file.PSPath
 }

Step 3:
Cross fingers and give 2018.1 a try!  You may have a few coding changes to make if you did not use macros to separate out builds. 

Example:
#if UNITY_2018_2_OR_NEWER
// put unity 2018_2 code here
#else
// put unity 2018._1 and below code here
#endif


Good luck!

No comments: