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

Possible BUG with BOUNDS

Discussion in 'Editor & General Support' started by xandeck, Jan 7, 2011.

  1. xandeck

    xandeck

    Joined:
    Apr 2, 2009
    Posts:
    563
    Hello,

    I tried a lot of things to get this work. I'm trying to rescale and resize the bounds of a Box Collider I have in a gameobject in my scene, other components are Text Mesh, Mesh renderer, a simple script and the box collider itself.

    I'm calculating the characters of some strings and then I need to resize and rescale my box collider to fill the collider area. But the code above returns me strange errors:

    Code (csharp):
    1.  
    2. var bounds = Bounds (Vector3.zero, Vector3 (1, 2, 1));
    3. collider.bounds = bounds;
    4.  
    The error:
    MissingFieldException: Field 'UnityEngine.BoxCollider.bounds' not found.
    Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.EmitPropertyDispatcher (System.Reflection.PropertyInfo property, SetOrGet gos)
    Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.EmitDispatcherFor (System.Reflection.MemberInfo info, SetOrGet gos)
    Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos)
    Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateSetter ()
    Boo.Lang.Runtime.RuntimeServices.DoCreatePropSetDispatcher (System.Object target, System.Type type, System.String name, System.Object value)
    Boo.Lang.Runtime.RuntimeServices.CreatePropSetDispatcher (System.Object target, System.String name, System.Object value)
    Boo.Lang.Runtime.RuntimeServices+<SetProperty>c__AnonStorey17.<>m__D ()
    Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
    Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
    Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Object[] args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
    Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
    Palavra.Start () (at Assets/Scripts/Palavra.js:117)

    I also tried with this:
    Code (csharp):
    1.  
    2. collider.bounds = Bounds (Vector3(20, posicaoBounds.y, posicaoBounds.z), Vector3(60, tamanhoBounds.y, tamanhoBounds.z));
    3.  
    The posicaoBounds and tamanhoBounds are just some int vars (tried with float too).
    This returns me the same error above. I also tried adding "new Bounds", etc...

    Somebody have a clue?

    And why its returning me something about the Boo language?
     
    Last edited: Jan 7, 2011
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Here's the error you should be getting:
    Property or indexer `UnityEngine.Collider.bounds' cannot be assigned to (it is read only)

    For a box collider, all you get is center and size. You can't use all the properties of a Bounds.
     
  3. xandeck

    xandeck

    Joined:
    Apr 2, 2009
    Posts:
    563
    I'm trying to do this:

    Code (csharp):
    1.  
    2. gameObject.collider.bounds.size.x = 60;
    3. gameObject.collider.bounds.center.x = 20;
    4.  
    And nothing happens with my bounds... nothing returns to me.

    :S

    Any ideas? Maybe I'm doing something wrong?
     
  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Again, you can't modify a collider's bounds directly. Put this idea of using the word "bounds" in your code, in the trash.
     
  5. xandeck

    xandeck

    Joined:
    Apr 2, 2009
    Posts:
    563
    Hmm... got it.
    Because when you said I get center and size, I understood that I could use only center and size properties of the bounds.
    Strange is in the manual it has a way for me to Construct a Bound, and there is nothing there saying its read only... so I thought I could modify this values through my code.

    But thank you, I will have to find another way to do what I want.
     
  6. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Bounds can be used for other things than colliders; that's why the class is called Bounds, not ColliderBounds. I agree that it should say (Read-only), though. It should be noted that all of the bounds that are used in the Unity API are read-only, but only Renderer.bounds is tagged as such. (Mesh.bounds is the other one, and like Collider.bounds doesn't alert you.)
     
  7. xandeck

    xandeck

    Joined:
    Apr 2, 2009
    Posts:
    563
    No problem, I found already another solution.
    Thank you.
     
  8. cowlinator

    cowlinator

    Joined:
    Mar 15, 2012
    Posts:
    69
    Hi xandeck,
    May I ask what your solution was? I am trying to do the same thing.
    It's strange to me that even now, the engine allows you to modify the size of colliders in the inspector, but not by script.