Used a simple scene with a simple component. Then built it on the Windows platform, and an error occurred when running:
ArgumentException: Cannot find TypeIndex for type hash 10113648094192326531. Check in the debug file ExportedTypes.log of your project Logs folder (<projectName>/Logs) the corresponding Component type name for the type hash 10113648094192326531. And ensure your runtime depends on all assemblies defining the Component types your data uses.
at Unity.Entities.Serialization.SerializeUtility.ReadTypeArray (Unity.Entities.Serialization.BinaryReader reader, Unity.Entities.Serialization.DotsSerializationReader dotsReader) [0x000ad] in <bfa9cee4093547fab46eac39ca0a96dc>:0
Component and Baker Code:
public struct HateFul : IComponentData
{
public float HateDistance;
public Entity Target;
public float3 Position;
public float TargetRadius;
}
public class SpAuthor : MonoBehaviour
{
class Baker : Baker<SpAuthor>
{
public override void Bake(SpAuthor authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new HateFul
{
Target = Entity.Null,
Position = float3.zero,
TargetRadius = 0,
HateDistance = 100,
});
}
}
}
Just a simple scene:
Build with both Mono and IL2CPP does not work:
Unity Version: Unity 6000.0.26f
Check:
1, Check ExportedTypes.log has HateFul
0x8c5ae55b75a3d783 - 10113648094192326531 - HateFul
2, add link.xml,not work
<linker>
<assembly fullname="Assembly-CSharp">
<!-- Preserve all members of the PlayerComponent -->
<type fullname="HateFul" preserve="all" />
</assembly>
</linker>
Any suggestions? Thanks!
If you don’t have conditional compilation preprocessor directives surrounding your component type (#if/#endif
), it’s likely an issue of full assembly inclusion. If you’re using assembly definitions, show the asmdef file or the Inspector view for the assembly definition owning the component type. This should be configured to be included in the build. If you’re not using assembly definitions (i.e. using predefined assemblies, though it’s not a bad idea to try using assembly definitions), the C# files should not be included in an editor-only folder (folders named Editor). It’s good practice to split runtime and authoring parts into different assemblies, at minimum keeping all your runtime data types in one assembly and your authoring components / baker in another, then keep the authoring / baker assembly editor-only.
Thank you for your response. Keeping the authoring/baker assembly editor-only is indeed a good idea.
Regarding this error, I found that reverting to Unity 2022 resolves the issue.
This might be related to the Scriptable Build Pipeline.
Unity 6 uses version 2.1.4, while Unity 2022 uses version 1.21.23.
You’re amazing!Thank you! I finally found the issue. It was because I added #if UNITY_EDITOR
to an attribute in the HateFul
component. This caused the attribute to exist when the entity was generated, but it wasn’t present at runtime. I used to rely on UNITY_EDITOR
to distinguish between editor and runtime, but this approach doesn’t work well in the DOTS workflow.
Glad you resolved it!
Do you mean a field? That would make sense, type hashes include the fields when being computed, the idea being to have a stable identity for a given type with a specific name as long as its data layout is the same. Making fields conditional would also change the data layout, which would be problematic since Entities uses byte-for-byte copying in many places. It’s best to avoid doing this, at least for types that will be serialized, like non-cleanup components and structs used in blobs.