How does Flecs.NET handle passing C# defined types to C++? #38
Replies: 2 comments 1 reply
-
The flecs core is type erased so it is up to the language binding to distinguish between different component types. In Flecs.NET, the first time a component is used, it does a symbol lookup to see if an existing entity exists and will bind to the existing entity if the size and alignment match. For example, if you registered a component named "Position" in C++ with an id of 100, and later tried to register a "Position" component in C#, the C# wrapper will use the id of 100 assuming both components have the same size and alignment. This id gets cached and reused for the duration of the application. I don't know if what I do in C# is possible in GDScript. A Godot binding for flecs is being worked on here that might give you some ideas on how to approach registering GDScript types in flecs. https://github.com/GsLogiMaker/glecs_godot_plugin/tree/master |
Beta Was this translation helpful? Give feedback.
-
Can C# managed objects be passed to flecs? That is a component with a C# string or list. If it is possable what structures would be required. I was thinking a dict of arc wrapped objects managed by component lifetime events outside of flecs. Systems that need to used objects in will reference the arc. This would avoid the need for pinning and other tricks but increase overhead. |
Beta Was this translation helpful? Give feedback.
-
Hi, I am trying to make some kind of addon/extension for Godot that enables the use of Flecs. There is an example of it here: https://github.com/paulfigiel/godot-flecs-sample, but it's limited in scope and functionality. It only really works if you intend to implement all your components/systems/etc. in C++ and just manage the calling of them from the editor.
I want to make something more flexible that has proper support for GDScript including defining new Components and Systems but I have ran into a bit of an issue. Basically because of the way that GDScript for Godot works, when you extend an object (e.g.
MyComponent_1
extendsComponent
) you don't actually get a new type in C++. This means that if I wanted to addMyComponent_1
andMyComponent_2
to an entity, it would actually overwrite the first component since from a C++ perspective they are both still aComponent
object.So this got me thinking, does Flecs.NET have the same issue? It must do something so that the C++ code can recognise the different types defined in C#. I tried having a look into your source code, but I am not amazing at reading other people's source code.
Any help would be appreciated
Beta Was this translation helpful? Give feedback.
All reactions