i have a few question about custom precondition and data access in general,
im using unity 2020.1.4f1 in a project using the default unity physics.
here is a very naive custom precondition that give an error on playtime (can use physicsscene only in main thread).
I will probably need something similar in a near future, and I don’t really actually know how to do that for the moment.
But I can help you with what I know from now.
First thing, you have to keep in mind that pre-condition are executed when the AI planner is building the decision graph, so it’s used to determine in advance if the action will be possible. That’s why the raycast must be able to be done on a possible future state of your world. Even if your code was compatible with job system, I don’t think the PhysicsScene will actually represent the world in the state the AI Planner actually knows.
To get the position of both actors, you have to use their Location trait:
But as said before, your TargetIsInSight function must rely on the world state as seen by the AI Planner.
The solution could be to have a trait for physics data (radius, shape, etc…) for both parameters and re-compute the raycast from that. One thing is certain: all your calculations must rely on trait data.