C# Limitations

In order to maintain compatibility with all our platforms and to create a secure experience, there are some limitations to C# scripting in the Spatial Creator Toolkit.

C# scripts are currently only available for Spaces made using the Spatial Creator Toolkit. Other package types (Avatars, Avatar Animations, etc.) do not support scripting.

All C# used in a space must be inside a single assembly definition. Referenced or sub-assemblies are not supported. Spatial does not support additive scene loading or scene management of any kind. Each space package uploaded may only use a single scene.

API Support

Spatial supports a limited subset of C# and the UnityEngine codebase.

Supported APIs

A significant portion of APIs from the following modules are supported:

  • mscorlib
  • UnityEngine.CoreModule
  • UnityEngine.AudioModule
  • UnityEngine.PhysicsModule
  • UnityEngine.AnimationModule
  • UnityEngine.UIModule
  • UnityEngine.UI
  • Unity.TextMeshPro
  • Creator Toolkit APIs

UnityEngine API Replacements

Some Unity APIs are very important but need to be partially restricted, or modified to operate safely inside spatial. The following APIs have replacements:

Unity is required to use the Spatial Creator Toolkit. You can install Unity from their official site.

Unsupported APIs

We can’t list all 5000+ currently blocked API calls here… but here are some common ones we have blocked:

  • Use of the unsafe Keyword
  • Editor scripts: allowed, as long as you move them to a Editor folder or use a #if UNITY_EDITOR directive
  • Most Application APIs like Application.OpenURL
  • Any SendMessage variant
  • Any System.Reflection APIs
  • System.IO.File System.IO.Directoryand any APIs dealing with the file system
  • Any Scene or SceneManagement related APIs
  • DontDestroyOnLoad: interferes with object lifecycles
  • TimeScale Time.fixedTimeDelta (setter) maxDeltaTime — no modification of time settings
  • DestroyImmediate: use Destroy instead
  • PlayerPrefs: use the Spatial Data Store
  • Resources: use AssetBundle
  • Camera.main, Camera.allCameras, Camera.current: use the Spatial Camera system, see Controlling the Camera
  • Networking APIs (UnityWebRequest www)
  • QualitySettings

If you need functionality of a certain API that is not supported, let us know! We might be able to expand our supported APIs or write similar functionality in a Spatial-unique API.

The best place to give this kind of feedback directly to the team is the Creator Toolkit section of the Spatial Discord.

While the Creator Toolkit has some limitations, you can still create a wide variety of experiences like you would with a regular Unity project!