Unity Dialogue System - Setting the Ports Connections

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
We have our nodes being drawn nicely. But there is one slightly problem, we have their design done, but we cannot even connect their ports. That's not what should be happening here, as we cannot move on without them connecting correctly. Thankfully, Unity allows us to override what ports a specific port can connect with by overriding their "GetCompatiblePorts" method. So let's go ahead to our GraphView script and start by overriding this method. In here, we'll need to return the list of ports that the actual selected port, which Unity called startPort, can connect with. Let's start by creating a variable of type "List<Port>" and I'll name it "compatiblePorts". At the end of this method we'll just return this list. Between the variable creation and the return we'll be iterating through the list of existing ports and add in the ports that we want to be able to connect with. Thankfully again, the GraphView has a variable named ports, which holds all the ports currently on the graph. However, because this is a UQueryState, we'll have to use its ForEach method instead of the old foreach loop we were using. And the element that will be here will be a port. Now this code will run for every port, and this is where we'll tell if the current port we're iterating through is compatible with our selected port or not. What we want is very simple: If our port is an output port, we want to be able to connect with all the other nodes input ports. That means we should not connect with our node ports nor with other output ports. If our port is an input port, we want to be able to connect with all the other nodes output ports. That also means we should not connect with our node ports nor with other input ports. So let's start by saying if the start port is the same as the current port ("if (startPort == port)"), return and move on to the next port. Then, if our start port node is the same as the port node ("if (startPort.node == port.node)"), return and move on to the next port. Of course, with this one, we don't really need the first if check statement, but I'll leave it in just to make sure. Then, as a last check, we'll say that if the start port direction is the same as the current port direction ("if (startPort.direction == port.direction)"), return and move on to the next port. Remember that direction is simply whether it's an input or output port. If none of these statements is true, then the selected port can be connected to the current port. If we save and head back to Unity, we should now be able to connect our ports correctly.
Info
Channel: Indie Wafflus
Views: 434
Rating: undefined out of 5
Keywords: Unity Dialogue System, Unity Dialog System, Unity Graph View, Unity Node, Unity Ports, Unity Node Ports, Unity UI Toolkit, Unity Dialogues, Unity Node Based Dialogue System, Dialogue System, Node Based Dialogue System, Unity Dialogs, Unity Visual Elements, Node System, Dialogue System Tutorial, Unity 2D, Unity, Unity Tutorial, Unity Dialogue System Tutorial, Unity 3D, Unity3D, Unity2D
Id: 2lTWWceEeEA
Channel Id: undefined
Length: 3min 38sec (218 seconds)
Published: Sun Jul 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.