Using Third Party Packages

Not all third-party packages are immediately compatible with the Spatial Creator Toolkit, but most packages can be adapted for the Creator Toolkit. Some popular third-party Unity packages have been successfully ported to be used with the Spatial Creator Toolkit, including Cinemachine, iTween, LeanTween, and more.

Porting a Package

Here are the general steps to port a third-party package to work with the Spatial Creator Toolkit:

  • Packages with precompiled DLLs are not supported.
  • All C# code must be in your Creator Toolkit Space’s C# assembly.
  • Packages must not use any of the banned APIs by the Spatial C# Scripting Runtime.
  • Copy the package’s source into your Creator Toolkit Space’s C# assembly folder.
  • If the package has any runtime assemblies of its own (i.e. .asmdef), those need to be removed and any missing references must be resolved. Assemblies in an Editor folder do not need to be removed.
  • Check for errors or warnings about banned APIs.
  • If there are banned APIs in editor-only code, ensure that the code is in a Editor folder, or that you use a #if UNITY_EDITOR directive.
  • For banned API usage in runtime code, remove the code if possible and replace with alternate APIs. You can find examples of this below in some of the packages that we've ported successfully.
  • In practice, we’ve found that many packages can be adapted with a moderate amount of effort. ⚠️ However, some packages cannot be supported if they have a hard dependency on banned APIs.

You can find a list of third-party packages with porting instructions here, including packages such as tweening and car control packages.

Addressables

See Addressables for a guide on how to use Addressables in your project. The Creator Toolkit already includes the Addressables package as a dependency.

Cinemachine

See Controlling the Camera or the Cinemachine Template for a guide on how to use Cinemachine in Spatial Creator Toolkit projects.

iTween

iTween is a simple animation library that can be ported rather easily since it’s one file. The only function used banned function is the CallBack function, which uses SendMessage to deliver callbacks for tweens. If you need event callbacks for tweens, you’ll have to implement them differently.

Porting instructions:

  1. Copy the files (Pixelplacement folder) into your assembly.
  2. Comment out the references to Application.OpenURL and Object.SendMessage

LeanTween

See Spatial-LeanTween for a forked version that works in Spatial Creator Toolkit projects and is used in production games.

DOTween Free

The DOTween license does not allow redistributing a modified version; here are the general instructions for modifying it to work in Spatial Creator Toolkit.

Porting instructions:

  1. Clone [DOTween] locally.
  2. From the _DOTween.Assembly folder, copy the DOTween, DOTweenEditor, and bin/Modules folders into your project under the folder containing your C# assembly.
  3. Remove AssemblyInfo.cs from DOTween/Properties and DOTweenEditor/Properties. You can remove the Properties folder too.
  4. Remove or comment out all functions beginning with AsyncAwait in DOTween/Modules/DOTweenModuleUnityVersion.cs
  5. Remove instances of using Resource.Load (for example, you could do DOTweenSettings settings = ScriptableObject.CreateInstance<DOTweenSettings>();)
  6. In DOTween/DOTween/Core/DOTweenComponent.cs
    • for all the lines beginning with Type modules = DOTweenUtils.GetLooseScriptType("DG.Tweening.DOTweenModuleUtils"); and ending with mi.Invoke(null, null);
    • replace with just this one line: DOTweenModuleUtils.Init();
  7. Remove or comment out GetLooseScriptType in DOTweenUtils.cs
  8. Comment out or remove all uses of DontDestroyOnLoad
  9. Command out or remove all helper functions that reference Unity’s camera (in DOTween/Plugins/Core/SpecialPluginsUtils.cs)
  10. For every file in the Editor folder, add a #if UNITY_EDITOR directive on the first line of the file, and a #endif on the last line of the file.
    • Normally, each Editor folder should have its own assembly definition. However, we found that for DOTween specifically this causes reference errors for non-exposed classes.
    • Sample unix commands to do this (replace /path/to/DOTweenEditor with your path to the editor folder)
#append #endif to all files
find /path/to/DOTweenEditor -type f -name "*.cs" -exec sed -i '' -e '$a\
\
#endif' {} \;

#prepend #if UNITY_EDITOR to all files
find /path/to/DOTweenEditor -type f -name "*.cs" -exec sed -i '' '1s/^/#if UNITY_EDITOR\n/' {} \;
#append #endif to all files
find /path/to/DOTweenEditor -type f -name "*.cs" -exec sed -i '' -e '$a\
\
#endif' {} \;

#prepend #if UNITY_EDITOR to all files
find /path/to/DOTweenEditor -type f -name "*.cs" -exec sed -i '' '1s/^/#if UNITY_EDITOR\n/' {} \;

Simple Car Controller

See the Simple Car Controller Template for a full example of using a third-party car controller from the Unity Asset store in Spatial.

Dynamic Bone

This package from the Asset Store allows you to use bones / splines. To be able to use it, be sure to change the CheckDistance function so that it doesn’t use Camera.main. Instead, you want to use the camera position:

Vector3 rtPos = m_ReferenceObject != null ? m_ReferenceObject.position : SpatialBridge.cameraService.position;
float d2 = (rtPos - transform.position).sqrMagnitude;
Vector3 rtPos = m_ReferenceObject != null ? m_ReferenceObject.position : SpatialBridge.cameraService.position;
float d2 = (rtPos - transform.position).sqrMagnitude;