How to implement Custom Commands
In this part of the documentation, you will find all the information you need about the Custom Command feature of the Command System, which is included in the Advanced Companion AI.
STEP 01 β ADD CUSTOM COMMAND TO COMMAND ENUM
The first step is to add your custom command to the commandenumeration. This enumeration is essentially a list that contains all the available commands for your command system. To locate the "Command Type" enumeration, follow these steps:
Open the "Blueprints" folder.
Navigate to the "Enums" folder.
Inside the "Enums" folder, open the "Command" folder.
Look for the file named "ACA_CommandType_Enum".
Here is the path for your
reference:/Content/Advanced_CompanionAI/Blueprints/Enums/Command/ACA_CommandType_Enum.uasset
Once you have found the command enumeration, you can proceed to the next step of adding your command as a new entry. Remember, the description is optional but can help keep everything organized.
STEP 02 β ADD CUSTOM COMMAND COMPONENT
To proceed, you need to add the custom command component to each actor where you want the command to be executed when selected in command mode. Adding the custom command component is necessary whenever you incorporate a custom command into the command system. This ensures that the command is properly executed by the command system. Remember to add the custom command component to every actor that will trigger the command. This step is crucial for the smooth functioning of the custom command within the command system.
To add the custom command component, follow these steps:
Select the actor that will serve as the trigger for your command.
In the details panel, locate and click on the "Add Component" button.
Search for the "ACA_Custom_Command_BP" component and add it to the actor.
By completing these steps, you will have successfully added the custom command component to the selected actor.
Now, select the component and look for the βCommandβ setting in the details panel. As you may see, this is the same enumeration, as the one where you just added your custom command. In the command setting, now select your custom command. Thatβs it, the component is setup.
STEP 03 β ADD CUSTOM COMMAND LOGIC TO COMPANION
So far, the system recognizes that there is a new command and knows when to trigger it. However, a problem arises when you start your game and attempt to use your custom commandβnothing happens. This is because you have not yet assigned your new command to your companion AI.
The command system operates by utilizing the command enumeration, which contains all available commands. By adding custom command components to objects within your level, the system determines where each
command should be triggered. However, it's important to note that by default not every companion is capable of executing all commands.
Each companion possesses its own array of available commands. This implies that the companion AI can only execute commands stored within its specific array. This feature proves beneficial as it allows you to assign distinct abilities to different companions. For instance, consider a dog companion and a human companion. The dog companion could possess the ability to sniff objects and provide information, while the human companion could utilize lock-cracking skills to open doors on your behalf.
As you can see, this feature grants you an incredible opportunity to create companions with diverse skills and abilities, thereby introducing an extensive range of gameplay mechanics. It opens exciting possibilities for enhancing the overall gameplay experience.
Well so now since you know how the command system works, how can you add commands to individual companions? Actually, there are 2 ways on how to do it:
The first method is quick but offers less diversity. Open the character blueprint of your companion AI and access the companion component. Look for the "Command Settings" where you will find the list of available commands for that companion. Note that any changes made in the character blueprint will affect all instances of that AI in your game. If you want different command behaviors for different instances of the same class, consider the second method.
The second method is suitable for placed instances of companions. Instead of modifying the character blueprint, select the placed instances in your level and access their companion component to adjust the command settings and add new commands. Keep in mind that this approach won't work for spawned companions, as they inherit settings from their parent class (character blueprint). If you require multiple companions with different abilities, consider creating separate companion character blueprints with distinct settings and only spawn the desired ones.
Well now since you know where to find the command settings and how you should proceed based on your preferences, how do you actually add a command to your companions.
The commands array already includes all pre-made commands by default. To add a new command, you can simply add a new array element. Open the element by clicking on the small dropdown, and you'll see a structure containing the command type and a behavior tree asset. The command type determines the specific command you want to add. Select the desired custom command. The behavior asset defines the logic that the AI should execute when performing the command. You have flexibility in designing this logic as per your requirements. Just remember to reset the command system once your logic is complete. We'll discuss more on this later.
Perfect! You know should have a working custom command. Go try it out by yourself. If you have any troubles, read this guide again and make sure you followed all instructions carefully. If this did not solve your problem, you can contact the support at any time. Thanks!
IMPORTANT β CUSTOM COMMAND LOGIC
While the previous steps have minimal risk of causing damage to the entire system, there is one crucial point where caution is necessary. Up to this point, we have only worked with the settings and have not made any modifications to the actual code or the behavior of the AI.
However, when you add your custom behavior tree logic for the custom command, you are actively modifying the behavior of the AI. This can potentially affect the overall functionality of the Advanced Companion AI. In this section, we will briefly explain how you can prevent errors when incorporating your own command logic. By the way, we recommend gaining a basic understanding of how behavior trees work before making any changes.
When creating a behavior tree, the nodes within it are executed by a composite. The execution order follows a left-to-right sequence. In other words, the node located furthest to the right is always executed last.
When creating your own behavior tree logic, you have considerable flexibility at the moment. However, there is one crucial point to remember. In each behavior tree responsible for a command, it is essential to include the "Reset Command System" task at the end. This node informs the main behavior tree that the command has been executed, allowing the AI to resume its original tasks.
Additionally, it is crucial to ensure that your logic functions properly and does not encounter any failures. Failure in logic can cause the companion to become trapped in an infinite command loop, continuously attempting to execute a command that always fails. This situation prevents the command system from resetting, and the main behavior tree mistakenly believes there is an ongoing command. If you are implementing logic that may fail due to in-game events, you can still incorporate such logic. Just remember to reset the command system whenever your command logic intentionally fails.
Having failing command logic doesn't necessarily lead to a complete system crash. In fact, most of the times the AI can still function adequately even when a command fails. However, it is considered a best practice to avoid implementing failing command logic to prevent potential bugs or unexpected behavior. It ensures the smooth operation of the system. You're welcome!
Last updated