Introduction
This tutorial will show you how to benefit from ‘Lightning Fast Compilation and Module Management for Unity’ if you are a game developer using scripting assets from the store or your own in-house developed scripting assets.
In this tutorial we will use plyGame as an example.
plyGame is a very good asset that I highly recommend if you are creating an RPG. I also see it very beneficial even if you are developing other kind of games.
plyGame has the following parts
- DiaQ (Source Include with the plyGame asset)
- DiaQEditor (Source Include with the plyGame asset)
- plyBlox
- plyBloxEditor
- plyCommon
- plyCommonEditor
- plyGame (Source Include with the plyGame asset)
- plyGameEditor (Source Include with the plyGame asset)
- plyRPG (Source Include with the plyGame asset)
- plyRPGEditor (Source Include with the plyGame asset)
If you have plyGame or other scripting asset from the asset store or your own in-house scripting asset you are using with the new game you are developing, chances are you want to customize, update and fix the asset to match your new game needs. Only in rare circumstances developers can benefit from off the shelf scripting assets specially for medium or large game studios creating custom cool games and not clones.
With ‘Lightning Fast Compilation and Module Management for Unity’ you don’t have to recompile the library each time you change a code even if it’s not related to plyGame. You will only recompile plyGame if you modified it. You can have your own private repository of the asset with a branch for your specific game.
Step 0 Importing plyGame
Import plyGame into your project.
Step 1 Creating 3 New Libraries
Choose Tools -> Fast Compilation -> Create New and enter the following settings:
- ”DiaQ” as Library name
- Check on ‘Compile Editor DLL’.
- Check on ‘Sync Unity’s Scripting Define Symbols’
- In the Advanced Settings
- Press ‘Get from .meta file’ of Runtime DLL GUID and choose Assets\plyoung\DiaQ\DiaQ.dll.meta
- Press ‘Get from .meta file’ of Editor DLL GUID and choose Assets\plyoung\DiaQ\Editor\DiaQEditor.dll.meta
Press Create button at the bottom of the window.
The step of using GUID from the existing DLL is to avoid any problems with already assigned MonoBehaviours. That way you don’t need to re-assign your behaviours.
Repeat the same steps, this time with name ”plyGame” but make sure you are selecting plyGame.dll.meta and plyGameEditor.dll.meta, then repeat again creating a new library with name “plyRPG” and plyRPG.dll.meta and plyRPGEditor.dll.meta.
Step 2 Adding plyGame Source
Create a temporary folder some where and extract into it DiaQ/Documentation/DiaQ-src.zip, plyGame/Documentation/plyGame-src.zip and plyRPG/Documentation/plyRPG-src.zip
You should now have the following temp directory structure
- plygametemp
- DiaQ
- DiaQEditor
- plyGame
- plyGameEditor
- plyRPG
- plyRPGEditor
Copy all the .cs source code files (keeping directory structure) from the following temp folder into the corresponding Fast Compilation folder.
- plygametemp\DiaQ -> \Assets\DiaQ\VisualStudioFiles~\NonPlugins\Runtime
- plygametemp\DiaQEditor -> \Assets\DiaQ\VisualStudioFiles~\NonPlugins\Editor
- plygametemp\plyGame -> \Assets\plyGame\VisualStudioFiles~\NonPlugins\Runtime
- plygametemp\plyGameEditor -> \Assets\plyGame\VisualStudioFiles~\NonPlugins\Editor
- plygametemp\plyRPG -> \Assets\plyRPG\VisualStudioFiles~\NonPlugins\Runtime
- plygametemp\plyRPGEditor -> \Assets\plyRPG\VisualStudioFiles~\NonPlugins\Editor
Pro Tips
‘Lightning Fast Compilation and Module Management for Unity’ automatically generates and updates csproj and sln files so you shouldn’t modify them manually and the original DiaQ.csproj or the other projects will not be used, so there’s no meaning to copy those into the fast compilation library.
Step 3 Setting Dependencies
Mark plyGame as a dependency for plyRPG. We can do that by choosing from the Libraries list plyRPG, then dragging plyGame to the dependency list in the lower part like this.
Step 4 Compiling the Code
Now that you have the new ‘Lightning Fast Compilation and Module Management’ version of DiaQ, plyGame and plyRPG we should delete the original DLLs. Please delete the following files
- Assets\plyoung\DiaQ\DiaQ.dll
- Assets\plyoung\DiaQ\DiaQ.dll.meta
- Assets\plyoung\DiaQ\Editor\DiaQEditor.dll
- Assets\plyoung\DiaQ\Editor\DiaQEditor.dll.meta
- Assets\plyoung\plyGame\plyGame.dll
- Assets\plyoung\plyGame\plyGame.dll.meta
- Assets\plyoung\plyGame\Editor\plyGameEditor.dll
- Assets\plyoung\plyGame\Editor\plyGameEditor.dll.meta
- Assets\plyoung\plyRPG\plyRPG.dll
- Assets\plyoung\plyRPG\plyRPG.dll.meta
- Assets\plyoung\plyRPG\Editor\plyRPGEditor.dll
- Assets\plyoung\plyRPG\Editor\plyRPGEditor.dll.meta
After deleting those files you will have some compilation errors. To solve this, please move ‘Assets\plyoung\plyBlox\Components’, ‘Assets\plyoung\DiaQ’, ‘Assets\plyoung\plyGame’ and ‘Assets\plyoung\plyRPG’ folders to a temporary place. We should get it back after successful compilation.
Press ‘Tools -> Fast Compilation -> Libraries List’ and press ‘Compile All’. You might get some errors depending on the version of source code and Unity you are using.
You might find errors in the following pattern, in that case skip this error to the following error to find out exactly what is wrong.
‘Unity_2018.1.6f1\Editor\Data\Mono\lib\mono\2.0\Microsoft.Common.targets: error : Assets\plyGame\VisualStudioFiles~\NonPlugins\Editor\obj\Release\plyGame Editor.dll does not exist at System.IO.File.Copy (System.String sourceFileName, System.String destFileName, Boolean overwrite) [0x00000] in <filename unknown>:0’
In our case the first error with useful information is this
‘Assets\plyGame\VisualStudioFiles~\NonPlugins\Runtime\FastCompileDLL_temp.csproj: System\GameGlobal.cs(223,64): error CS0619: `UnityEngine.GameObject.AddComponent(string)’ is obsolete: `GameObject.AddComponent with string argument has been deprecated. Use GameObject.AddComponent<T>() instead. (UnityUpgradable).”
compilation error
The error shows that plyGame library has a problem with the Runtime module. Open ‘Libraries List’ and in plyGame press ‘Open Solution’. Find the GameGlobal.cs file and go to line 220 and change #if UNITY5 to #if UNITY5 || UNITY_5_3_OR_NEWER
This is due to the plyGame developer probably compiling his DLL on Unity 5 and that’s the advantage of our plugin that things get compiled on the version of Unity on user end.
Pressing ‘Compile All’ again, the next error I got here is the following. If you setup dependencies right you shouldn’t face this problem.
‘Assets\plyRPG\VisualStudioFiles~\NonPlugins\Runtime\FastCompileDLL_temp.csproj: Game\Character\Actor\Actor.cs(16,45): error CS0246: The type or namespace name `IPersistable’ could not be found. Are you missing a using directive or an assembly reference?’
From the error I know this is the Runtime module of plyRPG Fast Compilation Library. Let’s go ahead and press ‘Open Solution’ of the plyRPG Library and navigate to Actor.cs line 16
You’ll find the class Actor implements interface IPersistable which is implemented in plyGame. What we want to is mark plyGame as a dependency for plyRPG. We can do that by choosing from the Libraries list plyRPG, then dragging plyGame to the dependency list in the lower part like this.
The next error you might have to handle is the following. This is because ?. operator is for C# 6 and Unity uses older version. However recent Unity has C# 6 and .Net 4.6 as an option. If you have this option disabled like myself, just edit the code to not use ?. symbol.
‘Assets\plyGame\VisualStudioFiles~\NonPlugins\Editor\FastCompileDLLEditor_temp.csproj: System\EdGlobal.cs(152,163): error CS1525: Unexpected symbol `?”
In our case we added this code
string fullName = null; if(asms[i] != null) fullName = asms[i].FullName;
And used the fullName instead of ?.FullName
The last step is to move back ‘Assets\plyoung\plyBlox\Components’, ‘Assets\plyoung\DiaQ’, ‘Assets\plyoung\plyGame’ and ‘Assets\plyoung\plyRPG’ from your temporary location to your Unity project.
You will find .mouseup depracated error, please correct it using .MouseUp
If you are an asset developer please check the next Tutorial to see how you as an asset developer can benefit from ‘Lightning Fast Compilation and Module Management for Unity’ and avoid the headache of maintaining source code and compiled versions of your assets.
Step 5 Using git for Source Control
Now that you have your own version of DiaQ, plyGame and plyRPG, you might want to create a git repository for each one of those separately to track your changes to the source code, and to be able to merge updates from the plyGame creator if there are any.