Unity Bug合集

文章列举了Unity开发中遇到的各种常见错误,如UniRx接口实现错误、UnityEngine依赖问题、WebGL兼容性问题、包管理错误、音频格式问题、事件处理和结构布局警告,以及废弃属性和版本验证错误,提供了相应的解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误: error CS0683: UniRx.ReactiveCollection<T>.IReactiveCollection<T>.get_Item(int)' explicit method implementation cannot implementUniRx.IReactiveCollection<T>.this[int].get' because it is an accessor

interface IExample  
{  
   int Test { get; }  
}  
  
class CExample : IExample  
{  
	//原
   int IExample.get_Test() { return 0; } // CS0683  
   //修改后
   int IExample.Test { get{ return 0; } } // correct  
}  
//原
T IReactiveCollection<T>.get_Item(int index)
{
    return base[index];
}

void IReactiveCollection<T>.set_Item(int index, T value)
{
    base[index] = value;
}

T IReadOnlyReactiveCollection<T>.get_Item(int index)
{
	return base[index];
}

//修改后
public new T this[int index]
{
	get
	{
		return base[index];
	}
	set
	{
		base[index] = value;
	}
}

错误:CS433:类型“MonoBehaviour同时存在于UnityEngineCoreModuleVersion0.0.0.0.Cultureneutral PublicKeyTokennull和“UnityEngineVersion0.0.0.0,CultureneutralPublicKeyTokennull中

删掉UnityEngine.dll

UNITY某个新版本后,把UnityEngine.dll的东西全部拆解到其它DLL了,主要核心功能在UnityEngine.coreModule.dll中,其它功能比如UnityEngine.Coremodule等。 而UnityEngine.dll完全是一个空壳,打开看里面全是空类,空代码。

错误:Unity打包WebGL在网页运行出现“To use diopen,you need yo use Emscript's linking support”问题解决方法。

解决方案

**错误:** $LOAD_DATA_FROM_SUBPACKAGE is not defined

1.检查打包的路径是否有中文,如果有中文,则可能会导致minigame/wasmcode/.webgl.wasm.code.unityweb.wasm.br代码分包文件无法生成

2.在转换小游戏时,要确保代码分包和资源首包的加起来的文件大小不能超过20M

错误:An error occurred while resolving packages: Project has invalid dependencies: com.unity.package-manager-ui: Package [com.unity.package-manager-ui@2.1.2] cannot be found Package com.unity.textmeshpro@2.0.0 has invalid dependencies: com.unity.ugui: Package [com.unity.ugui@1.0.0] cannot be found

把工程目录下的Packages目录中的manifest.json删掉, 然后再自动生成

错误:error CS0433: The imported type System.Xml.XmlNode is defined multiple times

方法一:将Plugins文件夹中System.Xml.dll移除

方法二:File - Build Setting - Player Setting - Other Settings - Scripting Runtime Version - 改为.Net 4.x

错误:Errors during import of AudioClip Assets/Resources/sounds/effects/Battle_TroopB_Shoot3.wav: FSBTool ERROR: The format of the source file is invalid, see output for details. FSBTool ERROR: Internal error from FMOD sub-system.
 

  • 方法一:检查音频文件的采样率:Unity可能无法处理某些特定的采样率。尝试将音频文件的采样率更改为44100Hz或48000Hz。

  • 方法二:重新导入音频文件:右键 - ReImport

错误:Compile error CS0079 : The event 'CustomEvent' can only appear on the left hand side of += or -=

//原
private Action<AndroidImagePickResult> m_OnImagePicked;

public event Action<AndroidImagePickResult> OnImagePicked
	{
		add
		{
			Action<AndroidImagePickResult> action = this.m_OnImagePicked;
			Action<AndroidImagePickResult> action2;
			do
			{
				action2 = action;
				action = Interlocked.CompareExchange(ref this.m_OnImagePicked, (Action<AndroidImagePickResult>)Delegate.Combine(action2, value), action);
			}
			while (action != action2);
		}
		remove
		{
			Action<AndroidImagePickResult> action = this.m_OnImagePicked;
			Action<AndroidImagePickResult> action2;
			do
			{
				action2 = action;
				action = Interlocked.CompareExchange(ref this.m_OnImagePicked, (Action<AndroidImagePickResult>)Delegate.Remove(action2, value), action);
			}
			while (action != action2);
		}
	}
	
public AndroidCamera()
	{
		this.OnImagePicked = delegate
		{
		};
		base._002Ector();
	}

//修复后
public event Action<AndroidImagePickResult> OnImagePicked;
public AndroidCamera()
{
	this.OnImagePicked = delegate
	{
	};
}

错误: error CS0619: ' xxxxxx ' is obsolete: ' xxxxx export is no longer supported .'

//原                                                                //改
RuntimePlatform.OSXWebPlayer                RuntimePlatform.OSXPlayer
RuntimePlatform.WindowsWebPlayer         RuntimePlatform.WindowsPlayer

//原
gameObject.transform.position = new Vector3(0f, 1f);
guiText.anchor = TextAnchor.UpperLeft;
guiText.alignment = TextAlignment.Left;
guiText.pixelOffset = pixelOffset;

//改
textComponent.rectTransform.localPosition = new Vector3(0f, 1f);
textComponent.alignment = TextAnchor.UpperLeft;
textComponent.alignment = TextAlignment.Left;
textComponent.rectTransform.anchoredPosition = pixelOffset;

RuntimePlatform.OSXDashboardPlayer //停止使用

错误ssembly ‘XXX.DLL’ will not be loaded due to errors: XXX references strong named ICSharpCode.SharpZipLib Assembly references: 0.85.5.452 Found in project: 0.86.0.518.Assembly Version Validation can be disabled in Player Settings “Assembly Version Validation”

Edit - Project Settings - Player - Other Settings - Assembly Version Validation

错误:error CS0636: The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)

//原
 [StructLayout(2)]
  private struct DoubleLongBytesUnion
  {
      [FieldOffset(0)]
      public double d;
  }

//改
 [StructLayout(LayoutKind.Explicit)]
  private struct DoubleLongBytesUnion
  {
      [FieldOffset(0)]
      public double d;
  }

错误:cannot explicitly call operator or accessor

this.get_myKick 改成 ()=>myKick

错误:提示参数shader为空

Edit - Project Settings - Graphics ; 将需要用到的shader拖拽进来

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值