Unity Package Types
Custom Collision, Layers, and Tags
What Is Effective Layer?
Internally, Spatial requires the objects in your scene’s to be on certain layers. Specifically, only layers
6 - 14 and
31 are allowed. The Effective Layer section will show you what layer your game-object will be set to when loaded in Spatial and gives you a drop-down of all the supported layers.
You will notice that everything besides layer 6-14 will be set to layer
In the Creator Toolkit you can customize the collision matrix for a select number of layers.
To do this navigate to your
Project Settings then open the
If you scroll down you will see the collision matrix for your project. Here you can enable or disable any of the collision settings for the layer pairs shown in green in the image below.
Utilizing Custom Layers
The basic Unity collision system will work as you expect when you change the matrix. If you are new to Unity make sure to check out their documentation on how the layer system works.
Additionally, inside Visual Scripting you can now raycast and target specific layers.
You can do this with a
Layer Mask to look for objects that are only on a particular set of layers.
DO NOT use Name to Layer functions
The names of your layers are not preserved when loaded in Spatial which means
Name To Layer nodes will most likely return
The following nodes will NOT work as expected because Spatial does not internally have a layer named
Tags are not supported
Although tags appear as just
strings, they function roughly the same as layers with an
ID. What this means is that when Spatial loads your bundle all the tags on your objects will be converted to the corresponding tag in the internal Spatial project. Unfortunately there is not really a path to re-map tags the way we do with layers, so we recommend you ignore them completely.
“Tagging” objects in other ways
Just because you can’t use the tags field doesn't mean you can’t “tag” an object with information. Here are the two main ways I recommend going about this:
1. Just Use Layers
The simplest method is just to use the limited custom layers as object IDs. For an action game you could keep all projectiles on one layer, and all enemies on another. Then you can modify your collision matrix so that projectiles can ONLY collide with enemies. Implicitly meaning anytime a projectile fires a collision event you know it has hit an enemy.
2. Tag with Visual Scripting Variables
With visual scripting you can add a
Variables component to any object and assign variables to it.
You can then attempt to access these variables from any gameObject by passing a gameObject into the object field on the
Get Variable node like shown below.
Be careful though! If you aren't confident that the gameObject in question will have the variable it is good to check for it using the
Has Variable node like the example below in order to avoid an exception.
Add link here
Add link here