Building a DLL with ECS ISystem Structs for Unity

Hi there!

Problem:
I’m developing an external solution containing content based on Unity’s Entity Component System (ECS), specifically utilizing ISystem structs. My goal is to build this solution into a DLL and integrate it into a Unity project.
However, when I try to use the DLL within Unity, I encounter an issue: the ISystem structs defined in my external solution are not recognized.

Research:
Initial research suggests that this approach might not be feasible. However, the available information on this specific scenario is limited.

Question:
Is there a viable approach to build a DLL containing ECS ISystem structs that can be successfully used within a Unity project?

It’s possible, but was a pain for me to figure out.
Follow the normal burst mod support
https://docs.unity3d.com/Packages/com.unity.burst@1.8/manual/modding-support.html

Once you load your dll, you then need to manually call the EarlyInit methods on the mono (not bursted) assembly.
So the code looks something like this.

var managedPlugin = Assembly.LoadFile(monoAssembly);
foreach (var type in managedPlugin.GetTypes())
{
    var method = type.GetMethod("EarlyInit", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
    method?.Invoke(null, null);
}
// then load bursted assemblies

This is usually handled for you by a IL processor.

2 Likes

Hey Tertle, thanks for this! Just wondering, when you say the non bursted assembly, do you mean the one(s) in the main unity project, or any mono assemblies being brought in as part of the external package?

Also, would you be able to share any info on what this early init call actually does/why it makes it work? Thank you :slight_smile:

Thanks for the reply!
I already tried it out, but it seems that, at least for Unity 6, this still doesn’t fully work.
I’m receiving:

ArgumentException: Type Apex.Testing.TestSystem couldn’t be found in the SystemRegistry. (This is likely a bug in an ILPostprocessor.)
Unity.Entities.WorldUnmanagedImpl.CreateUnmanagedSystemInternal (Unity.Entities.World self, System.Int32 structSize, System.Int64 typeHash, System.Int32 typeIndex, System.Void*& systemPtr, System.Boolean callOnCreate) (at ./Library/PackageCache/com.unity.entities/Unity.Entities/WorldUnmanaged.cs:469)

You’re loading it to late. It has to be done before type manager initialises. Unfortunately I’m about to jump on a plane so I won’t be able to post an example.