Troubleshooting custom control library compilation
Troubleshoot issues with custom control library compilation.
阅读时间1 分钟最后更新于 12 天前
This troubleshooting guide helps you resolve issues when compiling custom controls into DLLs.
Symptoms
When you compile custom controls into DLLs, you might encounter the following issues:
- Custom controls don’t appear in the UI Builder.
- Custom controls don’t serialize correctly when building libraries (DLLs).
Cause
UI Toolkit uses the UxmlElement code generator to support UXML serialization. However, when compiling custom controls into DLLs, the generated serialization code isn’t included by default, causing issues with element visibility and serialization.
Resolution
To resolve this issue, run the UI Toolkit source generator () during the DLL compilation process.
Unity.UIToolkit.SourceGenerator.dll-
Find the source generator file in your Unity installation. It’s typically located at:.
<Unity Installation Path>\Data\Tools\Unity.SourceGenerators\Unity.UIToolkit.SourceGenerator.dll -
Add the source generator as an analyzer in your library project’sfile within an
.csproj:<ItemGroup><ItemGroup> <Analyzer Include="path\to\Unity.UIToolkit.SourceGenerator.dll" /></ItemGroup> -
Compile your library as usual. This triggers the source generator, which generates the required UxmlSerializedData class for your custom control.