#Native Containers as a ref with Burst?

1 messages · Page 1 of 1 (latest)

astral holly
#

I'm probably screwing something up somewhere...

I need to read a managed component so I'm using SystemAPI.ManagedAPI, however I also want to use the Burst Compiler in the rest of the code so something like this:

[BurstCompile] 
public void OnUpdate(ref SystemState state)
{
    NativeList<E> E = new(Allocator.TempJob);
    method(ref E)  

    //schedule job with new values
}

[BurstDiscard] 
private void method(ref NativeList<E> E)
{
    //add to E with values from managed component
}```
When burst is disabled it works just fine but with Burst the referenced list isn't changed. Am I doing something wrong or do I cut my losses and just not use burst (considering I'm only scheduling a job, performance won't take a big hit. I just want to learn if I can do this in the future)
vast monolith
#

[BurstDiscard]
just means delete this code when using burst

#

it won't exist

astral holly
#

oh, I thought it just meant to not compile... (leave it as normal cs code)

#

bit misleading

vast monolith
#

you can't leave burst (without a bunch of work to pin methods and create function pointers)

vast monolith
#

but that is correct in that the method is just discarded when compiling it

astral holly
vast monolith
#

you really need to know what you're doing

#

i would say it's done very very rarely

#

the overhead would usually cost more than the benefits

astral holly
#

would be like when a method needs something managed but also requires burst critically?

#

but at that point you'd just jobify it instead of having it all in OnUpdate for example

#

oh well... bye bye burst (and hello to +0.0001ms frame time)

vast monolith
#

i.e. splitting into 2 systems or something

#

it's also unlikely you'll find any tutorial or instructions on how to leave burst

#

which should kind of hint at how rare it is to do

astral holly
#

Thanks again!

vast monolith
#

but just for completeness you need to marshal a function pointer from your method

#

and just pass that via pointer to a function pointer

#

if you're marshalling a non-static method you'll need to pin the underlying class so the GC doesn't move/delete it

#

i.e. Marshal.GetFunctionPointerForDelegate