❔ How can I delete a component

For example: AddComponent<RigidBody>(); //for add rigid body //But how i delete that rigid body¿
6 Replies
Anton
Anton2y ago
Destroy(GetComponent<...>()) $code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Anton
Anton2y ago
$unity
arion
arion2y ago
public static void RemoveComponent<T>(this UnityEngine.MonoBehaviour mb) where T : UnityEngine.Component
{
if (!mb.TryGetComponent<T>(out var component))
return;
UnityEngine.Object.Destroy(component);
}
public static void RemoveComponent<T>(this UnityEngine.MonoBehaviour mb) where T : UnityEngine.Component
{
if (!mb.TryGetComponent<T>(out var component))
return;
UnityEngine.Object.Destroy(component);
}
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.