Search Unity

Question Batched Boxcasts multiple times between frame updates

Discussion in 'Entity Component System' started by NoYouSirName, Aug 8, 2021.

  1. NoYouSirName

    NoYouSirName

    Joined:
    Mar 11, 2020
    Posts:
    13
    I'm using unity to control some peripheral electronics which can respond to commands sent at nearly 200hz.

    To generate the commands, I need to perform a batch of boxcasts based on the mouse location.

    My laptop can't handle 200fps, but we don't actually need a serious framerate, so I thought I could just schedule the same pair of jobs (casting job and cleanup job) multiple times every time Update() is called, using dependsOn to make sure they run in order, so that I will always have a chain of jobs running independently of the main thread (using the solution that allows managed code to get the current mouse position in the cleanup job).

    However things got a lot more complicated (and this is all pretty complicated for me anyway) when I found out I can't actually raycast in a job, but have to use BoxcastCommand and schedule it on the main thread.

    This would mean I can't have the whole thing run independently (sans adding to the chain of dependsOn-s by scheduling more) of the main thread and I will have to be at the mercy of invokeRepeating to schedule the whole thing very quickly, which also means when the frame is updated, the regularly scheduled casting will have to wait and I'd have to skip sending a few commands.

    Is there some way I can achieve what I had in mind - running the whole thing as independently of the main thread as possible?

    The objects in the layers relevant to the casting do not move at all (though I may be asked to allow some object deformation later), so I expect that may spare me some trouble.