🧑‍🤝‍🧑
Advanced Companion AI: Documentation
  • General Information
  • Extended Product Description
  • Update Logs
  • What makes this product special?
  • Reviews
  • Useful Unreal documentation
  • đź“‹Documentation
    • Quick Setup
    • Settings Explained
    • How to implement Custom Commands
    • The Projection System
    • Included Follow Modes
    • The Area Detection System
    • Using the Command System
    • Built-in AI Perception System
    • The Neutral Area
    • What are Interactable Objects?
  • Weblinks
    • 📺Our YouTube Channel
  • 🤝Join our Discord Community
  • 📹Advanced Companion AI Playlist
  • ⬇️Download Gameplay Tags .ini
  • ⬇️Download playable demo
  • Privacy Disclaimer & Contact Information
Powered by GitBook
On this page
  • Default Commands
  • Whats the difference between selecting the AI and selecting in command mode?
  • Entering the Command Mode
  • Get Command Information
  • Apply a Command
  • Stopping a Command or leaving Command Mode
  1. Documentation

Using the Command System

In the following you will find an explanation on how the command system works, enabling you to optimize your workflow and understanding of the Advanced Companion AI.


Default Commands

Using the command system, you give the player a great way to interact with the AI. Additional to the custom commands that you are able to add using the Custom Commands feature, the command system comes with a bunch of predefined commands that are already integrated and ready to use:

Move Command

The Move command can be used to send the AI to a specific location in your world. To achieve this, simply select the AI in command mode, point to a valid AI location anywhere in your world (must be within range of the command system), and apply the command by pressing the "E" key. (Default setting)

Wait Command

If the AI is currently waiting (after using the Wait command), you can use the Stop Wait command to make the AI resume its normal behavior. To use the Stop Wait command, as with the Wait command, you must point at the waiting AI while it is selected in command mode.

Stop Wait Command

When the AI is currently waiting (after using the Wait Command) you can use the Stop Wait Command to make the AI continue its normal behavior. To use the Stop Wait Command, just as with the Wait Command you have to point at the waiting AI while selected in command mode.

Interact / Inspect Command

When the AI is selected in command mode and you point at an interactable object in your game world, you will see the "Inspect" command pop up in the UI. When the command is applied, the AI will walk to the interactable and execute the appropriate logic assigned to that interactable's Ident component.

Attack Command

When the AI is selected in command mode and pointed at an actor that has the "Enemy" tag, it will execute its attack logic on that actor. You can set your own attack logic by setting a custom behavior tree in the Companion Component.

Add Custom Commands

You can also dynamically add custom commands without doing any changes to the original code. Check out the “custom commands” documentation for more details on how to implement your own custom commands.

Whats the difference between selecting the AI and selecting in command mode?

When using the command system, there will be some definitions that may be confusing to you as someone who did not develop the system. Two definitions we want to clarify are: Selected and Selected in Command Mode.

Selected

When you approach your AI companion and look at it from a certain distance, you will see a small UI element pop up that gives you some basic information about the AI, its name, and a prompt (press "E" to enter command mode).

This is the state we refer to as the AI being selected. It means that the AI "knows" that the player is currently trying to interact with it in some way, which results in the AI focusing the player and waiting at its current location as long as it is selected (looked at).

Selected in Command Mode

When you actually do the prompt that is shown when the AI is generally selected, you will switch to command mode. For now, the AI will just behave as it would when normally selected, focusing on the player while waiting.

The only difference now is that the AI "knows" that the player is currently commanding it, which will affect the AI's in-game behavior later on. The AI will now wait for the player to select and apply a command, which it will then execute.

Entering the Command Mode

Before the AI can receive and perform any commands, the player has to enter the command mode. The logic for this is mostly provided by the Player Component.

Inside of the player component, a ray is permanently fired forward from the players camera. As soon as the ray detects a companion, the companion is notified that it is selected by the player which does affect the AI behavior. Also, the HUD Widget is informed to edit its elements accordingly. As soon as the companion is selected, the companions AI controller is enabled to receive input from the player.

Now when the player presses “E” and the AI isn’t already in command mode, the AI will be informed that it is under command, the widget changes its elements, and the “Command Detection” is started in the player component.

Get Command Information

When the AI is in command mode, the player component executes the command detection logic. This is another ray sent forward from the player camera that checks what command (if available) should be executed for the currently hit actor.

When hitting an actor, the “Determine Command Type” function is called. This function first checks if the hit actor has the custom command component which would mean that it is containing a custom command. If so, it gets the command type from the component and returns it. If the actor does not own a custom command component, the system will check if any other of the predefined commands is suitable for this actor. For example, if the actor has the “enemy” tag it will be considered as an enemy and the “Attack” command type will be returned.

When the function is finished, a structure will be filled with values, needed by the companion AI to execute the command. The structure does for example contain the command type and the location of the hit actor. If you want to add custom commands, it might be that you have to add custom data to this structure if needed by your command.

Apply a Command

Now that the system has all the information about the currently available command, the player is able to actually tell the AI to perform the command. Until now, all we did is collecting information about what actor is currently selected, what command could be used on this actor and gathering information needed for the AI to perform its command.

If the player now presses “E” again, the system will see that the AI is already commanded so it won’t set the AI in command mode again, but instead it would make the AI actually perform a command. To achieve this the AI is told that it has an active command. Afterwards it is given the needed information and it is told that it is not actively commanded by the player anymore (having an active command and being commanded is a difference).

The AI now knows that it has an active command and has all the necessary information to perform this command.

Stopping a Command or leaving Command Mode

There is currently no way to just stop an already given command. The only way to “stop” a command is to replace it with a new one. That’s just how the command system works. For example, if you told the AI to attack an enemy, you could cancel it by giving the AI a “move” command, back to your position.

If you want to leave the command mode while trying to give the AI a command, this is fairly simple. When in command mode, the AI controller is able to receive input from the player. When pressing the “TAB” Key, you leave the command mode and can return to normal gameplay. Please note that leaving the command mode does not mean that you are cancelling the currently active command.


PreviousThe Area Detection SystemNextBuilt-in AI Perception System

Last updated 1 year ago

đź“‹
How to implement Custom Commands
Command Bay (DEMO)
Selected AI
AI Selected in Command Mode