- Home /
Unity 2018.1 - IJobParallelFor: Getting color of object which was hit by a raycast
Hello together,
I am using the new ECS Jobsystem and looking for a solution for my problem. In my application I have to perform many raycasts and do some calculations afterwards. To increase the performance I am using the RaycastCommand.ScheduleBatch() command. The following job (IJobParallelFor over all raycasthits) is depending on the previous job and does some calculations with the RaycastCommand-result–array.
Unfortunately I need the colors of the objects, which were hit by the raycasts. Because of the fact that it is impossible to call .GetComponent method from a workerthread, I am looking for another way to get this information.
Normally, without the Jobsystem, I would do something like this:
Color color = hit.collider.GetComponent<Renderer>().material.color;
But inside a job, this is impossible.
1. Is there a way to use the RaycastCommand and store the InstanceIDs of the objects, which were hit by the raycasts?
2. Or is there another way to perform the above code within a job?
Thanks a lot in advance for your help. With best regards
Answer by JuanuHaedo · Nov 17, 2018 at 07:11 PM
Were you able to fix this? If not, it would be nice to see how you are actually putting things up with some more code. The Jobs System is pretty simple, but it does need some rules to be followed, in order to work..
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Changing two different objects renderer colour 1 Answer
I'm trying to change a material, texture or color and it doesnt work 0 Answers
Get color from another script. 0 Answers
How to access multiple components of a component at once? 2 Answers