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

Centering Colliders

Discussion in 'Editor & General Support' started by Enialis_Nailo, Jul 17, 2020.

  1. Enialis_Nailo

    Enialis_Nailo

    Joined:
    Jul 12, 2020
    Posts:
    8
    How can i make it so that when I add a collider component it centers on the gameobject? Every time I try to add a collider to a prefab the collider starts at the center of the scene instead of the prefab.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Are you talking about a prefab in the prefab "scene", or just modifying a prefab instance in a scene?
     
  3. Enialis_Nailo

    Enialis_Nailo

    Joined:
    Jul 12, 2020
    Posts:
    8
    I'm talking about adding a box collider to a prefab in scene view. Is there a way to make the colliders center default to the center of the prefab in the prefab editing mode? I'm not trying to do this through a script as part of gameplay, just trying to add colliders to the walls in a roll a ball type game for a cert prep-course. In every video tutorial I've seen when they add a collider component to a prefab while in scene mode the colliders center starts equal to the prefabs transform.
     
  4. Enialis_Nailo

    Enialis_Nailo

    Joined:
    Jul 12, 2020
    Posts:
    8
    I think I've isolated the problem, i was attaching the box collider to the parent gameObject for my walls, I had to add the collider component to the child gameObject for it to center properly on the prefab. Can anyone elaborate on exactly what's happening here? I'm assuming this is intended behavior and something to do with inheritance between parent/child gameObjects.
     
  5. ibbybn

    ibbybn

    Joined:
    Jan 6, 2017
    Posts:
    193
    When you add any collider it's looking for meshes attached to the same gameobject to calculate it's bounds and the center. If it can't find a mesh it uses the gameobjects transform as a center and uses standard bounds.
     
  6. Enialis_Nailo

    Enialis_Nailo

    Joined:
    Jul 12, 2020
    Posts:
    8
    Okay, Thanks for clarifying that for me!