#Loading Components and systems from DLL at runtime

1 messages · Page 1 of 1 (latest)

uncut ermine
#

Hi, i need to be able to load custom components and systems (mods) at runtime and was looking for some guidance, previously i was loading the dll via Assembly.LoadFile() and tried to add the contained component to an entity which threw an error due to not knowing about the component type at compile time. Currently i am loading a DLL using BurstRuntime.LoadAdditionalLibrary() (still no idea if that's how i should do this) that contains a component, but have no idea how would i now get the component.
this is all happening before typemanager.initialize/default world creation
Any insight on how people are loading and registering components/systems at runtime would be helpful, thanks for reading my rambles

scarlet oyster
#

you do it as soon as possible

#

I had success loading mod mono in old 0.51 version

#

couldn't load burst

uncut ermine
#

that makes sense, gonna try now thanks issue

uncut ermine
#

!code

grim fjordBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

uncut ermine
#

im doing something wrong still, i get the same error ArgumentException: Unknown Type:TestComponent All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType]. here is the code https://gdl.space/ofoviledaz.cs if i can't get it to work no biggie, i got a hybrid workaround it would just be nice if i could do it properly

pine tangle
#

Means you likely haven't loaded early enough

#

Also loading bursted isystem requires a bit of extra work and hacks

#

You need to manually call some code gen methods however I have it working (and discussed a bit in general)

#

You have to load before type manager initialises

uncut ermine
#

thanks for taking the time! is disabling the auto bootstrap and calling in awake not early enough? i have no idea how to call it earlier

pine tangle
uncut ermine
pine tangle
#

Discussion I had about this with another user

#

Not sure they got it working but i detail what I did

pine tangle
uncut ermine
#

thanks for the info, i really need to learn about the codegen and reading through source code before i try do this way again i think, hybrid approach will do for now

scarlet oyster
#

You need to call either before assemblies loaded or right after

uncut ermine
#

thanks yeah i called it with the after assemblies loaded attribute turtle mentioned, looks like the component gets added with out error, now unsure how i can get the component with getcomponent as a dynamic type think i need to make it into a generic method and set the type that way as i cant find a getcomponent method that allows me to use the type if its a variable like state.EntityManager.AddComponent(ent, CustomScripts.customScripts[0].parentType);

scarlet oyster
#

Otherwise just use TypeManager API

uncut ermine
#

I didn't think It is implicit I can't use the type variable as T in the method it says < cannot be applied to a method group or similar, I'll have a look at typemanager docs to see what to use thanks!

uncut ermine
#

MethodInfo methodInfo = typeof(EntityManager).GetMethod("GetComponentData", parameterTypes);
MethodInfo genericMethod = methodInfo.MakeGenericMethod(CustomScripts.customScripts[0].parentType); worked couldnt get the type to be accepted by any getcomponent methods systemapi or entitymanager otherwise, i hate reflection so much xD

scarlet oyster
#

just create dynamic type handle using your type

#

and get your data as bytes

uncut ermine
#

thats so much better, thanks for the help,if we didn't have you and tertle (and a few others) ecs would be so much harder, much appreciated

scarlet oyster