
Composite
Composite nodes are at the core of the decision-making capabilities of Behavior Trees in Unreal, and understanding how they work is key.
There are three kinds of Composite nodes: Selector, Sequence, and Simple Parallel. The last one has been added recently, and you will find that by using a combination of Selectors and Sequences, you will be able to cover most of your cases. Here is how they work:
Selector: This kind of node will try to find one of its children to execute, which means it tries to find either a branch (so another Composite node attached as a child) or a Task (another child, but it is a leaf) to execute. So, the Selector starts from the left-most child node and tries to execute it. If it fails (either the Task failed to be executed, or the whole branch failed), then it tries the second left-most, and so on. If one of the children returns Success, which means that either the Task has been completed or a whole branch has been completed, then the Selector reports Success to its parent, and stop executing other children. On the other hand, if all the children of the Selector report a fail, then the Selector reports a fail to its parent as well. In the following screenshot, you can see what the Selector node looks like:

Sequence: This kind of node works a bit like the opposite of the Selector. To report a success to its parent, all of the Sequence's children must report a success. This means that the Sequence will start executing the left-most child node. If it is a success, it carries on with the second left-most, and so on if it is successful as well. If all the children until the right-most are a success, then the Sequence reports a Success to its parent. Otherwise, if just one the children fail, then the Sequence will stop executing its children, and report a fail to the parent. In the following screenshot, you can see what the Sequence node looks like:

Simple Parallel: This is a particular kind of Composite node, which is used in specific cases. In fact, it can only have two children. The left-most child must be a Task, whereas the right-most child can be either a Task or a Composite (thus giving birth to a sub-tree). The Simple Parallel starts to execute both its children in parallel, although the left-most is considered the main one. If the main one fails, it reports a fail, but if the main one succeeds, then it reports a success. Based on its settings, the Simple Parallel, once it has finished executing the main task, can either wait until the end of execution of the sub-tree or directly report success or fail the main one to its parent and stop executing the sub-tree. In the following screenshot, you can see what the Simple Parallel node looks like. Please note that it is possible to drag only two children, in which the left-most must be a Task (the purple block is the draggable area):

In this way, Composite nodes can "decide" which tasks to execute, based on what their children report (fail or success), and the Composite node reports back (either fail or success) to their parent. Even if the only-child of the root (which is a Composite node) reports back a success to the Root, then the tree has been executed with success. A good Behavior Tree design should always allow for success.