Hi all.
I’m working on WaveMaker (my asset for simulating waves) and It needs heavy use of the Unity Job System and Raycasts.
I encountered some problems.
The first one is that I cannot throw rays to a specific object via RaycastCommand the same way we can do it with a single ray with Collider.Raycast. We can only pass a LayerMask. The problem with layers is that there are not many and I don’t want people to add a layer just for this asset. In some projects they are extremely optimized and there are not many available. Having the possibility to pass just one object to test would be a great improvement. In fact due to the need of giving a “max number of hits” that has to be as small as possible, I get hits to unwanted objects, unless I use masks which I don’t really need.
Adding them on runtime just for this process seems a little hacky for me.
The other problem, which makes my process slow even though I take advantage of Jobs everyhwere, is that RaycastCommand returns:
_raycastResults = new NativeArray<RaycastHit>(size, allocationType).
handle = RaycastCommand.ScheduleBatch(_raycasts, _raycastResults, 64, handle);
But I cannot use that NativeArray with RaycastHits inside a Job to gather and manage the results because the way to tell if a reycast hit a given object, you need to access the Collider methods, which is a class that is inside UnityEngine and Jobs cannot work with those.
In fact, this problem is tied to the previous one. Since I cannot throw rays to just one object, I’m forced to check which is the collider detected inside my job. I need an intermediate non-multithreaded process that copies all the hitData into another data struct and slowing down the process very much, because I have tens of thousands of results.
So even though RaycastCommand was created to use with jobs, I can’t work with its results at all.
Am I missing something here?
Thanks