Possible BUG with BOUNDS

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:

var bounds = Bounds (Vector3.zero, Vector3 (1, 2, 1));
collider.bounds = bounds;

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+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:

collider.bounds = Bounds (Vector3(20, posicaoBounds.y, posicaoBounds.z), Vector3(60, tamanhoBounds.y, tamanhoBounds.z));

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?

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.

I’m trying to do this:

gameObject.collider.bounds.size.x = 60;
gameObject.collider.bounds.center.x = 20;

And nothing happens with my bounds… nothing returns to me.

:S

Any ideas? Maybe I’m doing something wrong?

Again, you can’t modify a collider’s bounds directly. Put this idea of using the word “bounds” in your code, in the trash.

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.

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.)

No problem, I found already another solution.
Thank you.

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.