LoginSignup
6
0

More than 5 years have passed since last update.

Unityエディタ拡張で、Componentを削除する。

Posted at

下記AnimationコンポーネントをUnityエディタ上で削除する場合

extension.cs

if (gameObj.GetComponent<Animation>()) //Animationコンポーネントが存在するか
{
    // Destroy(gameObj.GetComponent<Animation>());  // -> 消せず、、
    // GameObject.Destroy(gameObj.GetComponent<Animation()); // -> 消せず

    Animation animComponent = (Animation)gameObj.GetComponent<Animation>();
    GameObject.DestroyImmediate(animComponent); // -> 消せた
}

DestroyImmediateを使うと即座に消える。

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