3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Renderer.boundsの値が変更できない

Posted at

今回の記事はとても短いです。

本題

Renderer系(SkinnedMeshRendererなど)のboundsをスクリプトから変えようとすると、

renderer.bounds = new Bounds();
//-> Property or indexer 'Renderer.bounds' cannot be assigned to -- it is read only [Assembly-CSharp]
renderer.bounds.extents = new Vector3();
//->Cannot modify the return value of 'Renderer.bounds' because it is not a variable [Assembly-CSharp]

というようなエラーが出ます。

解決策は、Renderer.boundsではなく、Renderer.localBoundsを使います。
例えば、Rendererの範囲を(1,2,3)に変えたいなら、

Bounds bounds = renderer.localBounds;
bounds.extents = new Vector3(1, 2, 3);
renderer.localBounds = bounds;

とします。Transform.positionの扱いととても似ていますね。

まとめ

いかがだったでしょうか。今回は、かなり基礎的な話だったと思いますが、ネットで調べても全く出てこなかったので記事化しました。
メッシュ周りをいじるのはVRMとかを触るときくらいでしょうか...?筆者も、VRChat用に作成したアバターを調整するプログラムを作っていたときに本記事の問題に直面しました。
今回のように基礎的な話から、コアな話までしていきます。もしお役に立てましたら、フォロー等よろしくお願いいたします。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?