#Burst cannot compile, when a bool is inside a ref IComponentData
1 messages · Page 1 of 1 (latest)
are you sure your NativeArray with tuple is valid?
yes everything compiled
after adding IsBuilding today and doing some other tests the bool has to be at fault
when I change bool to BoolAB (a byte enum with True and False) it works too
yep I know but Unity should have done some stuff for that
I mean, they could write their own C# ig 😅
I could swear I read threads about that Unity has done somthing for the bool internally
but I'd rather them stick to .net and migrate to modern version
nah
it's not blittable in C#
so forced to deal with it
wait but why does this compile then?
because it's inside of bursted method
not at root
when you burst compile static method, this exact method declaration will be entry point into native world
so all parameters must be blittable
and passed by reference
even though the struct has a non blittable bool?
it's not an entry point into native code
it is part of native code
consider entry point is like extern method
I see, I will take a look at all that then
it has all same limitations basically
A proper bytebool struct would be more helpful.
Do you mean something like that?
ups
you said byte
byte instead of bool for the value
holy that's way more than I thought of 😅 😂
that's really good, don't mind me reusing the code 👀
it surely makes my boolean code looks "normal"
yeah I get the chills, whenever I have to do an if like that
BoolAB val...;
if (val == BoolAB.True)
thanks for sharing! :)
Wait, isn't this doc https://docs.unity3d.com/Packages/com.unity.entities@1.1/manual/components-unmanaged.html explicitly saying that unmanaged components can store both blittable types and bools?
Yes totally fine to store them and use them
You just can't use them on function pointers
If you've ever tried to write a native function with a bool field and then marshal can it from c# you'll know the issue
Ok, I've never marshalled bools tbh
So the issue here is that this component is used in a bursted method
Which is like almost use case number one for unmanaged components, but the docs say nothing about it
Yeah I'm not sure why OP is even using one instead of just a bursted job but that was the issue
I knew I have read it somewhere 😅
I had to move my function up to the ISystem, since it's now being used by 2 Jobs, instead of 1 and the function wouldn't Burstcompile without the ref/in
why would it not be burst compiled?
i assume your OnUpdate is burst compiled since it's ISystem
so any method it calls is burst compiled - it doesn't need the attribute that's just creating a second separate compiled method
I can check tomorrow again, but I had problems with that a few months back
Oohh I didn't know, that's good to know. I have been putting the burst compile Attribute over every valid function (except jobs)
yeah that's not great
But I am still far away from being an expert, since I just started with dots a few months back 😅
basically once you're in burst, it's very hard to leave burst
you have to do some real magic to call code that isn't bursted from burst
so if you're in a bursted OnUpdate anything called from there is bursted
(same as a bursted job execute method)
when using actual entities you only need [BurstCompile] OnUpdate (create/destroy etc) and the top of jobs
What about a Utils class which has manged functions as well?
And bursted functions
if it's called from burst
it's bursted
[BurstCompile]
public struct Job : IJob
{
public void Execute()
{
MyUtility.DoMagic();
}
}```
DoMagic is always bursted
Should I keep a seperate burst compiled class for bursted code? Since the ide is telling me to do that constantly
if DoMagic is not burstable, burst will error at you
it won't run it in mono
it will make the entire job run in mono until you fix it
But I put the attribute once over a struct (for my quad tree) and the CPU got tanked
unless you're calling a method from a MonoBehaviour or something, you should never have the attribute on it
Ohh yeah I know that, comes up now and then
So you recommend that I should put the attribute away from the functions which are in the Utils class?
yes
if you're calling this utility class from ISystem OnUpdate or a job then it doesn't make sense to have the attribute on the utility class
Alright thanks!
But what if the function is being accessed from ISystem and Mono. Is it still burst compiled for both calls for only the ISystem one?
it'd only be compiled for the ISystem
Ohh I see
but the question is, is the function heavy enough to actually benefit from burst
because calling a function pointer is not free
small functions that you burst compile will run slower
than just running them from mono
I understand, that makes sense
Cool, tomorrow I will look through my whole code and adjust it 😂
Thanks again for clearing things up ✌️
if you do this, then passing bool is totally fine