Is this possible or the correct way? I need some Blob data in a job with some other data. I’m basically using the below code but I’m pretty sure its not working correctly. Do I need to get it by ref somehow?
var dudewtf = GetSingleton<WaypointWalker>();
var jobtuner = new TurnTowardsjob()
{
blobbypoints = dudewtf.Waypoints.Value.Waypoints
};
edit: So it seems like getting the Blobdata with Getsingleton works but setting it in that manner somehow makes all the values incorrect. I’m presuming because its not by ref?
Yes, you need to get everything in the blob (including the blob itself) by ref.
They’ll be adding a compiler check at some point to make non-ref access an error.
I’m about to publish an updated custom package that has a lot helpers for this type of use case (along with unit tested examples). Stay tuned. I’ll put an update to this thread when I do.
Thanks I’m curious how would I get the blob by ref then, because neither of the below code works.
ref var dudewtf = ref GetSingleton<WaypointWalker>();
ref var tempblob = ref Blobbypoints;
Edit: Nevermind the second statement seems to be working now for some reason, but still the values arent the correct values, maybe I have a bug somewhere else though.
So I still cannot get the Blob data’s to work inside a job I’ve tried every combination and method I can think and cannot find the right code. I can get the blob data fine outside the job I can check the values and they all come back correct. But inside the job the data just becomes garbage, incorrect data no matter what I do it seems. Here’s the code I currently have if anyone can figure out what I’m doing wrong.
public class TurnTowardsWhatever : JobComponentSystem
{
public EntityQuery ma_query;
protected override void OnCreate()
{
RequireSingletonForUpdate<PauseSystemsCompTag>();
ma_query = GetEntityQuery(typeof(WaypointWalker));
}
//[BurstCompile]
struct TurnTowardsjob : IJobForEach<Translation, Rotation, ToCurrentWaypoint>
{
[DeallocateOnJobCompletion]
public BlobArray<float3> blobbypoints;
public void Execute(ref Translation transit, ref Rotation rutate, ref ToCurrentWaypoint dudud)
{
ref var tempblob = ref blobbypoints;
float3 heading = tempblob[dudud.value] - transit.Value;
for (int i = 0; i < tempblob.Length; i++)
{
Debug.Log("Current Waypoint inside job is equal to " + tempblob[i]);
}
heading.y = 0f;
rutate.Value = quaternion.LookRotation(heading, math.up());
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
//var dudewalker = GetSingleton<WaypointWalker>();
//ref var tempblob = ref dudewalker.Waypoints.Value.Waypoints;
var dudewmaypoint = ma_query.GetSingleton<WaypointWalker>();
ref var duddly = ref dudewmaypoint;
// for (int i = 0; i < duddly.Waypoints.Value.Waypoints.Length; i++)
// {
// Debug.Log("Current Waypoint outside job is equal" + duddly.Waypoints.Value.Waypoints[i]);
// }
var jobtuner = new TurnTowardsjob()
{
blobbypoints = duddly.Waypoints.Value.Waypoints
};
return jobtuner.ScheduleSingle(this, inputDeps);
}
}
Always pass the BlobAssetReference or the struct containing the BlobAssetReference into the job and access what you need from the job.
And in case you are wondering why (warning: technical): Blobs rely on relative addressing hardware to gain speed-ups when reading the data while allowing the structure to be dynamically-sized with respect to type. In consequence, the blob can’t be split up as it will break the relative addressing. For passing stuff into a job you have to give the job the root address. And for passing stuff around while inside of a job you have to use ref so that the offset addresses are captured relative to the root.
I’ve posted a thread for the utility framework I mentioned earlier: A DOTS utility package: Hydrogen.Entities
Might have some other useful examples for other folks who stumble on this thread.