Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 5 terrain collider

Discussion in 'Editor & General Support' started by Armynator, Mar 5, 2015.

  1. Armynator

    Armynator

    Joined:
    Feb 15, 2013
    Posts:
    59
    Hello,

    since the update to Unity 5 my terrain collider isn't updating anymore while the game is running.

    I made a simple terraforming script wich is changing the terrain, but the character just stays in the air, because the collider isn't changing.

    Short video to show what I mean:

    (The character plays the jumping animation all the time because the player isn't grounded)

    After stopping the game and saving the scene the collider is updated, but not after just restarting the game (or while the game is running, as needed).

    Is there any way to update the collider by script, or am I doing anything wrong?

    I tested this, but it didn't worked/updated the collider:
    Code (CSharp):
    1. this.GetComponent<TerrainCollider>().terrainData = this.GetComponent<Terrain>().terrainData;
     
    Last edited: Mar 5, 2015
  2. TechnicianStudios

    TechnicianStudios

    Joined:
    Aug 6, 2012
    Posts:
    60
    Sorry. This is not an answer but I am having similar issues with the terrain. My chracter walk through the terrain when I'm walking to a hill, but when I move to a flat area near the hill my cheater hose up from the terrain like there's a hill. I double checked and see ify character is set up wrong but when I used the unity 5 3rd person controller and FPS controller. I get similar errors. I think the terrain in unity 5 is broken.
     
  3. L_Vi

    L_Vi

    Joined:
    Mar 5, 2015
    Posts:
    9
    I'm experiencing the same thing.

    [Steps]
    New Project
    Add Standard Assets such as character controllers
    Create Terrain
    Add basic grass texture
    Paint some basic hills
    Smooth them out
    Add character controller (doesnt matter which, its the same result)
    [/steps]

    The result is that the character is never where it should be against the terrain. Either floating above it, or going through and underneath it.
     
  4. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,169
    It doesn't even update all the time in the editor. :) I have to exit out of unity and reload to get it to recalculate the terrain collider.
     
    MichaelJT likes this.
  5. Jmanpie

    Jmanpie

    Joined:
    Oct 7, 2012
    Posts:
    132
    I thought you always had to destroy and recalculate coliders anyway? didn't you use to have to do that for unity 4?
     
  6. Dino000

    Dino000

    Joined:
    Dec 15, 2013
    Posts:
    4
    I can confirm that problem. It's the same thing with my terrain. A quickfix is:
    Select Terrain
    Terrain Collider -> Terrain Data -> Select your terrain again
     
  7. JustinLudlow

    JustinLudlow

    Joined:
    Jan 6, 2015
    Posts:
    2
    Confirmed here as well. Unity 5 Personal with a brand new project and one terrain only. Build a small hill, smooth it, through in the default character controller and run around and fall through the terrain. Its exactly what L_Vi is saying.
     
  8. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    500
    I'm getting similar issues with Unity 5 terrain. I can run up one side of a hill but walk through it on the other side. I think its a collider issue since even though i walk through the hill i dont fall !
     
  9. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,169
    This is reported fixed in the next patch.
     
  10. Sherasoft

    Sherasoft

    Joined:
    Nov 17, 2013
    Posts:
    8
    Not yet fixed in version 5.1.1f1 so far, a quick semi-normal fix is to save you scene or re-assign the Terrain data file to the terrain object. you can try to save and re-open Unity too if the previous two methods didn't work for you.

    Cheers
    Shera Studios
     
  11. DanJa512

    DanJa512

    Joined:
    Dec 14, 2015
    Posts:
    18
    After a bunch of rummaging around, it turns out that if you have multiple terrain data assets named the same thing, Unity will use height data for the collider of the first terrain asset it finds that matches what you have selected for the collider.

    I was able to fix this issue by manually renaming all terrain assets in my project folder to distinct names, and re-creating the terrain collider components on each one.
     
    Kurt-Dekker likes this.
  12. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,501
    Good catch DanJa... best practices for Unity terrain should probably include specifying unique names for each terrain asset, as well as storing each one in its own separate directory separate from the others.
     
  13. lucas216erickson

    lucas216erickson

    Joined:
    Apr 7, 2016
    Posts:
    1
    Old thread, I know, but it's one of the first things that comes up. I found a solution. I tried deleting and adding terrain colliders through script, and I found out that the problem was in the timing. This solution is kind of hack-ish and you would probably need to run it during a loading screen:

    Code (CSharp):
    1. void Start()
    2.     {
    3.         Destroy(GetComponent<TerrainCollider>());
    4.         StartCoroutine(LateStart(0.1f));
    5.     }
    6.  
    7.     IEnumerator LateStart(float waitTime)
    8.     {
    9.         yield return new WaitForSeconds(waitTime);
    10.         while(GetComponent<TerrainCollider>() == null)
    11.         {
    12.             gameObject.AddComponent<TerrainCollider>();
    13.             GetComponent<TerrainCollider>().terrainData = GetComponent<Terrain>().terrainData;
    14.         }
    15.     }
    Basically what it does is it deletes the terrain collider, waits 0.1 seconds, and then creates a new one and sets the terrain data to that of the terrain. Hope this helps anyone who is still stuck on this issue.