C
Join ServerC#
help
❔ How can I delete a component
IIván12/24/2022
For example:
AddComponent<RigidBody>();
//for add rigid body
//But how i delete that rigid body¿
AddComponent<RigidBody>();
//for add rigid body
//But how i delete that rigid body¿
AAntonC12/24/2022
Destroy(GetComponent<...>())
AAntonC12/24/2022
$code
MMODiX12/24/2022
To post C# code type the following:
```cs
// code here
```
Get an example by typing
If your code is too long, post it to: https://paste.mod.gg/
```cs
// code here
```
Get an example by typing
$codegif
in chatIf your code is too long, post it to: https://paste.mod.gg/
AAntonC12/24/2022
$unity
MMODiX12/24/2022
Aarion12/24/2022
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);
}
AAccord12/25/2022
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.