Hands-On Artificial Intelligence with Unreal Engine
上QQ阅读APP看书,第一时间看更新

Smart Links

Smart Links can be enabled and disabled at runtime using the "Smart Link Is Relevant" boolean variable. You can also notify surrounding actors of this change. By default, it is not relevant (it isn't used in the sense that the link is not available), and there is only a single Smart Link per Nav Proxy Link.

Please note, and don't get confused: The Smart link can be in two states: Enabled and Disabled. However, if the link is actually "present/exists" (for the Navigation Mesh), that is another property ( Smart Link Is Relevant), which in other words means that the link is " active" for the Navigation System (but it can still be in the Enabled or Disabled state).

Unfortunately (at least for the current version of the Engine), these are not visible in the Editor, which means that the Start and End positions need to be set manually.

However, let's go through the settings of a Smart Link:

  • Enabled Area Class: This is the Nav Area that the Link assumes when it is enabled. The default is NavArea_Default.
  • Disabled Area Class: This is the Nav Area that the Link assumes when it is disabled. This means that, when the Link is disabled, it can still be traversed if a crossable area is assigned (e.g. when the link is disabled, we might want to have a very high cost to cross, but we still want it to be possible to traverse it. Of course, the default is NavArea_Default, which means that it is not crossable.
  • Link Relative Start: This represents the Start point of the link, relative to the position of its Nav Link Proxy.
  • Link Relative End: This represents the End point of the link, relative to the position of its Nav Link Proxy.
  • Link Direction: This specifies in which direction the link works. The possible options are as follows:
    • Both Ways: The link is bidirectional (remember that the AI needs to be equipped to traverse the Link in both directions; e.g. over a ledge, the agent needs to be able to fall from it (one direction of the link) and jump (the other direction of the link).
    • Left to Right: The link is only crossable from the Left end to the Right one (the agent still needs to have the ability to go in that link direction).
    • Right to Left: The link is only crossable from the Right end to the Left one (the agent still needs to have the ability to go in that link direction).
Although the options of this parameter label the end points of the link as Left and Right, they refer to the Start and End point of the link. Alternatively (this may be better since the link can be bidirectional), Link Relative Start and Link Relative End refer to Left and Right.
  • Link Enabled: This is a boolean variable that determines whether the Smart Link is enabled. This value can be changed at runtime, and the link can "notify" surrounding agents/actors that are interested in such information (see later for more info). The default value is true.
  • Smart Link Is Relevant: This is a boolean variable that determines whether the Smart Link is actually "active", that is, if it is relevant or whether we should ignore it. The default value is false.

These are the main settings regarding a Smart Link.

It's worth mentioning that Smart Links can actually do more than just connect Nav Meshes. They have a series of functions to handle agents that are traversing the Link. For instance, by opening the NavLinkProxy.h file, we can find the following functions:

  /** called when agent reaches smart link during path following, use ResumePathFollowing() to give control back */
UFUNCTION(BlueprintImplementableEvent)
void ReceiveSmartLinkReached(AActor* Agent, const FVector& Destination);

/** resume normal path following */
UFUNCTION(BlueprintCallable, Category="AI|Navigation")
void ResumePathFollowing(AActor* Agent);

/** check if smart link is enabled */
UFUNCTION(BlueprintCallable, Category="AI|Navigation")
bool IsSmartLinkEnabled() const;

/** change state of smart link */
UFUNCTION(BlueprintCallable, Category="AI|Navigation")
void SetSmartLinkEnabled(bool bEnabled);

/** check if any agent is moving through smart link right now */
UFUNCTION(BlueprintCallable, Category="AI|Navigation")
bool HasMovingAgents() const;

Unfortunately, these functions are outside the scope of this book, but I invite you to read the code to learn more about them.

Previously, we mentioned that the Smart Link can broadcast information regarding its status change at runtime to nearby agent/actors. You can change how the Smart Link broadcasts this information with the Broadcast settings, which are just below the Smart Link ones:

These settings are quite intuitive, but let's go through them quickly:

  • Notify when Enabled: If true, the Link will notify agents/actors when it gets Enabled.
  • Notify when Disabled: If true, the Link will notify agents/actors when it gets Disabled.
  • Broadcast Radius: This specifies how far the broadcast should go. Every agent that is outside this radius will not get notified about the change of the Link.
  • Broadcast Interval: This specifies after how long the Link should repeat the broadcast. If the value is zero, the broadcast is repeated only once.
  • Broadcast Channel: This is the trace channel for broadcasting the change.

This concludes our discussion on Smart Links.