I cannot find information anywhere on this and am getting conflicting answers when asking around on discord servers.
I am trying to setup the ability to interact with my waypoint graph when a user clicks an edge i want it to split the edge that is clicked into 2 edges and create a node at the position they clicked. Buti t also first needs to check the clicked point overlaps an edge.
It’s not clear what the best practice is to handle this. I get the mouse click from regular monobehaviours using the regular input stuff and raycasting to a plane etc.
The things i’ve been told so far is a monobehaviour should never have a reference to a system so i shouldn’t directly call a public function in a system that does the logic and checks.
So this leaves two options:
Option 1:
The monobehaviour itself should have the logic that creates the two new edge entities and the new node and connects them via an entity command buffer and then play that back by passing in the entitymanager reference, since its a one time operation based on user clicks. But not sure how would i would do the initial check that the mouse is over an edge.
Option 2:
In the monobehaviour similar to option one, create an entity with a custom component like “SplitCommand” which contains the split point.
Create a system that looks for entities with “SplitCommand” and then that system has the logic for splitting and creating the new edges/nodes in an OnUpdate which would run on the next frame. But this still doesn’t help with first checking if the point overlaps an edge by creating such an entity split command. (And i am not even sure if its good practice for monobehaviours to ever create entities).
I’ve been told by different people that both these options are not the correct way to do it…yet no one offering up the actual correct way to do it.
Both of these have issues.
Option 1 means the logic is outside of a system and in a monobehaviour, but option 2 means theres no way to return a true/false if the split was not possible due to no overlaps, so theres no way to inform the user it was not possible. If i do pre-checks that it overlaps an edge i would need a system to do that test but the click is generated in a monobehaviour so how do i do such a test in the click script, the whole this is confusing as heck.
There is absolutely zero explanation by Unity in their docs, all their examples are pretty rudimentary on how we are suppose bridge mono land to ECS land in these situations? What are the best practices for this?