-
-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unity support #100
Comments
I will do that once i have some time :) Pretty busy rn with my thesis. Arch sources can not be used, nugets however should be usable even if they make use of higher language features. |
In Decentraland we are already doing a PoC using |
First of all, it's probably the coolest thing I've heard in a long time and makes myself kind of proud too :) Also saw that you created a SystemGroups framework, I'll link it on the github page, maybe others are interested in it too ^^ To the second... there we, unfortunately, come across a limitation of C#. As an alternative there would be Unsafe.SizeOf, but this does not provide a type overload and is therefore only limited usable. The easiest option here is to never use managed structs. Or... and here comes your solution... register them yourself beforehand. public struct ManagedStruct{ public List<int> SomeInts{ get; set; } }
// Register
var componentType = new ComponentType(ComponentRegistry.Size - 1, typeof(ManagedStruct), 8, false); // 8 = Size in bytes of the managed struct.
ComponentRegistry.Add(componentType);
// Use
var entity = world.Create(new ManagedStruct()); |
Great, it may work out, I will give it a try. Thank you
Sure, feel free |
Perfect! Lemme know if it works for your case :) |
I can confirm that the proposed solution works nicely with Unity IL2CPP with both a manually calculated size
|
Great to see that it works! :) 33013b9 recently added automatic size detection for managed structs. That makes use of reflection during the component registration. Should also work on unity and will reduce the boilerplate a bit in the future ^^ |
That's actually great so there will be no boilerplate. IL2CPP though will not generate the generic version of
may not work in Unity. It should not be critical as all usual paths I saw so far were via an explicitly mentioned generic |
I assume that's because Unitys IL2CPP strips out most reflection code, especially if not mentioned before... correct? For the future i could look into unity specific way. If i saw that correctly, unity has their own SizeOf API. |
You can read more about IL2CPP Code stripping here. Essentially, the most relevant part is the "Annotate roots using a Link XML file" section with generics examples. This is how the limitation can be circumvented. When it comes to generics with value types it's not like they are stripped out, it's rather the AOT compiler does not generate them at all. For every value type, the size needed to allocate the type itself and the values on the stack (for methods invocations for instance) is different. Unlike the ref type when it can be always treated as an For example,
It's a perfect example of the necessity for the AOT compiler to know about the generic type ahead. If the code is not generated (and without |
When I have time I will create a |
Ah i see. However a link.xml or the [Preserve] attribute. Have you ever tried the [Preserve] attribute? In the example with the Unsafe API, we could theoretically create a Unsafe.SizeOf wrapper, add that attribute and call it. Wouldnt that work? Might be easier ^^ But haven't tried it yet. |
|
@mikhail-dcl i've copied minimal struct of your project ( plugins folder with arch, and meta files, and copy dll of source generators and their meta files ) but faced exception (maybe problem with source generator) using System.Runtime.CompilerServices; public partial class TestTagSystem : BaseSystem<World, float>
}
maybe you faced something like that? |
sorry guys i found the answer |
I have developed Arch.Unity as a library to integrate Arch into Unity. This includes support for Conversion workflows (GameObject to Entity), fast queries integrated with the C# Job System, Hierarchy Windows and Inspectors that can track Entity, and a unique layer to integrate Arch.System with PlayerLoop. I hope this helps Arch support Unity. (Sorry if this is not what I should be posting here...) |
Can you provide a unity example?
The text was updated successfully, but these errors were encountered: