0
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?

Unity 6.5で、長らくObsoleteだったrigidbodyなどのプロパティーが完全に削除される

0
Last updated at Posted at 2026-06-13

Unity 6.5では、長らく Obsolete 扱いだった Component.rigidbody などのプロパティが完全に削除されます。

これまで Component.rigidbody プロパティは、「コンパイルエラーになる設定の Obsolete」として定義されており、GetComponent<Rigidbody>() メソッドの呼び出しへ書き換えるよう促されていました。

しかし Unity 6.5 では、このプロパティ自体が完全に削除されるようです。

また、Component.rigidbody 以外にも、GetComponent() メソッドの呼び出しに置き換えるよう促されていた、多数の ObsoleteGameObject / Component のプロパティが削除されます。

該当する変更は、Unity 6.5.0b11 のリリースノートにも記載されています。

Scripting: Removed: Removed Component.rigidbody. Use Component.GetComponent() instead. With this change, Component.rigidbody will no longer be automatically upgraded to Component.GetComponent() and will instead have to be manually changed by the user.

Scripting: Removed: Removed GameObject.rigidbody. Use GameObject.GetComponent() instead. With this change, GameObject.rigidbody will no longer be automatically upgraded to GameObject.GetComponent() and will instead have to be manually changed by the user.

Scripting: Removed: Component.audio has been removed. Use GetComponent() instead.

Scripting: Removed: Removed GameObject.audio. Use GameObject.GetComponent() instead.

つまり、これまでは API Updater によって GetComponent<T>() への自動変換が行われていましたが、Unity 6.5 以降は自動変換されず、ユーザーが手動で修正する必要があります。

Unity 6.4まで

まずは、Unity 6.4 までの挙動をおさらいします。

Unity 6.4 で次のようなコードを書くとします。

using UnityEngine;

public class ComponentSample : MonoBehaviour
{
    void Start()
    {
        var propertyRigidbody = rigidbody;
    }
}

この場合、次のような「Component.rigidbody プロパティは Obsolete なので、代わりに GetComponent<Rigidbody>() を使ってください」という内容のコンパイルエラーになります。

error CS0619: 'Component.rigidbody' is obsolete: 'Property rigidbody has been deprecated. Use GetComponent<Rigidbody>() instead. (UnityUpgradable)'

また、このコードがあると API Updater が動作し、GetComponent<Rigidbody>() メソッドへの書き換えが促されます。

スクリーンショット 2026-06-14 082913.png

次の公式ドキュメントによると、少なくとも Unity 5 系のころから、このような API Updater の仕組みは存在していたようです。

※Unity 5 のリリースは 2015 年ごろなので、かなり以前から存在していた挙動です。

Unity 6.5から

次に、Unity 6.5 での挙動を確認します。

Unity 6.5 で次のようなコードを書くとします。

using UnityEngine;

public class ComponentSample : MonoBehaviour
{
    void Start()
    {
        var propertyRigidbody = rigidbody;
    }
}

Unity 6.4 までは Obsolete によるコンパイルエラーでしたが、Unity 6.5 では次のように「rigidbody という名前は現在のコンテキストに存在しない」というエラーになります。

error CS0103: The name 'rigidbody' does not exist in the current context

つまり、Component.rigidbody は完全に削除されました。

そのため、Unity 6.5 以降では次のように明示的に GetComponent<Rigidbody>() を呼び出す必要があります。

using UnityEngine;

public class ComponentSample : MonoBehaviour
{
    void Start()
    {
        var propertyRigidbody = GetComponent<Rigidbody>();
    }
}

GameObject.rigidbody を使っていた場合も同様に、次のように書き換える必要があります。

var propertyRigidbody = gameObject.GetComponent<Rigidbody>();

まとめ

Unity 6.5 では、長らく Obsolete 扱いだった Component.rigidbodyGameObject.rigidbody などのプロパティが完全に削除されます。

Unity 6.4 までは、これらを使うと Obsolete によるコンパイルエラーになり、API Updater によって GetComponent<T>() への書き換えが促されていました。

しかし Unity 6.5 以降では、プロパティ自体が存在しないため、次のようなエラーになります。

error CS0103: The name 'rigidbody' does not exist in the current context

そのため、古いプロジェクトを Unity 6.5 以降へ移行する場合は、事前に Component.rigidbodyGameObject.audio などの古いプロパティを検索し、明示的な GetComponent<T>() 呼び出しへ置き換えておく必要があります。

var rb = GetComponent<Rigidbody>();
var audioSource = GetComponent<AudioSource>();

実際に削除される対象は Unity 6.5 のリリースノートを確認してください。

Unity 5 時代から長らく残されていた互換用 API が、Unity 6.5 でいよいよ削除されるのですね!

0
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
0
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?