- Home /
Prefab's collider2d.bounds.size is not set
Hi.
Could you tell me when prefab's collider2d.bound.size is loaded?
I have a simple script in which I want to print prefab's size. Unfortunately size is always equal to (0.0, 0.0, 0.0) despite in editor it is equal to 170x205.
If I create new object from the same prefab in editor and then pass it to the script, size is set properly.
using UnityEngine;
public class SimpleScript : MonoBehaviour
{
public GameObject prefab;
private void Start()
{
Debug.Log(string.Format("Prefab size: {0}", prefab.collider2D.bounds.size));
}
}
Comment
Best Answer
Answer by Vladimir-Shafran · Aug 13, 2014 at 11:18 AM
If you wanna get size of collider2d like in Editor, you must use something like this
gameObject.GetComponent<BoxCollider2D>().size.x
gameObject.GetComponent<BoxCollider2D>().size.y
When you use value “bounds” you get size in world’s units
Your answer
Follow this Question
Related Questions
Project size 1 Answer
Prefabs with sprites, make them all same size 0 Answers
How to stop rotation of prefabs? 0 Answers
Find right mesh for collider 1 Answer