[Unity]移除物体的所有组件

本文介绍在Unity中如何手动移除预制体上的无效或不再需要的组件,以解决Missing组件问题。这些组件通常是由于缺少关联的脚本文件或者脚本已被删除导致的。
摘要由CSDN通过智能技术生成

 

 

预制体的无效组件,只能 手动 移除,保存预制体。

Missing的组件,通常情况 是 工程的Asset不存在该脚本,或者是脚本已经被删除。

 

...
	/// <summary>
	/// 移除 物体 的所有 组件
	/// </summary>
	/// <param name="gameObject">要移除的 物体 的组件</param>
	public static void RemoveComponent(GameObject gameObject)
	{
		List<Component> comList = new List<Component>();
		Debug.Log("RemoveComponent:" + gameObject.name);
		foreach (var component in gameObject.GetComponents<Component>())
		{
			if (component != null)
			{
				//comList.Add(component);
				Debug.Log("RemoveComponent:" + gameObject.name + "/" + component.GetType());
			}
			else//当组件为无效组件,或者Missing Component,则为空
			{
				Debug.Log("RemoveComponen
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值