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:
mscorlibUnityEngine.CoreModuleUnityEngine.AudioModuleUnityEngine.PhysicsModuleUnityEngine.AnimationModuleUnityEngine.UIModuleUnityEngine.UIUnity.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:
Application.OpenURL: UseSpaceService.OpenURLCamera.main: SeeCameraService
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
unsafeKeyword - Editor scripts: allowed, as long as you move them to a
Editorfolder or use a#if UNITY_EDITORdirective - Most
ApplicationAPIs likeApplication.OpenURL - Any
SendMessagevariant - Any
System.ReflectionAPIs System.IO.FileSystem.IO.Directoryand any APIs dealing with the file system- Any
SceneorSceneManagementrelated APIs DontDestroyOnLoad: interferes with object lifecyclesTimeScaleTime.fixedTimeDelta (setter)maxDeltaTime— no modification of time settingsDestroyImmediate: useDestroyinsteadPlayerPrefs: use the Spatial Data StoreResources: useAssetBundleCamera.main,Camera.allCameras,Camera.current: use the Spatial Camera system, see Controlling the Camera- Networking APIs (
UnityWebRequestwww) 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!