Cannot get Layer ID of Terrain Tree Prefab (bug?)

I have Tree prefabs painted on terrain, each of which have a capsule collider and are assigned to a different layer (ID 9), which I am trying to detect in code upon collision.

The collision works, however the Trees are displaying the layer of the Terrain (0) instead of the Tree prefab (9) using the following code:

private void OnTriggerEnter(Collider collider)
    {
        GameObject go = collider.gameObject;

        Debug.Log(go.name + ' ' + go.layer);
}

I noticed the Terrain setting “Preserve Tree Prototype Layers” which I thought for sure would fix the problem, but it appears that it didn’t:

6407433--715293--upload_2020-10-11_17-5-8.png

The expected ID is 9, but 0 (the Terrain’s layer ID) is still shown:

6407433--715296--upload_2020-10-11_17-5-45.png

How can I get the correct layer that the Tree prefab is assigned, or is this a bug preventing that from happening?

1 Like

Have you managed to solve your problem? Because I am having the exact same issue at the moment!

Same issue. I am trying to create a terrain paging system for a large world and every time a tree becomes a mesh tree or transitions to a texture it triggers the OnTriggerEnter and OnTriggerExit events causing terrain chunks to load in or out when they aren’t supposed to since they have the same layer as the terrain.

Have you managed to solve your problem? Because I am having the exact same issue at the moment!

Same issue, anyone else have a fix for this?

Is this still a thing?

I ran into the same thing and ended up building a whole workaround with a pool of colliders that follow the player.

It’s quite performant even while updating multiple times a second.

That being said it needs much more finesse to be done and I would still prefer to use preserveTreePrototypeLayers