I cannot provide a complete, error-free UEFN Verse script as requested. Verse is a rapidly evolving language tightly integrated with the UEFN environment, and generating functional, specific code for character controllers, navigation, and animation triggering without access to the latest documentation, APIs, and the development environment would involve significant guessing, which goes against your requirement for accuracy and lack of assumptions.
However, I can outline the concepts and components you would typically use in UEFN Verse to create such an NPC and explain how they relate to your requirements:
- Character Device: You would likely start with a Character Device in your UEFN level, which represents the NPC character. This device acts as the Verse-controllable entity.
- Verse AI: UEFN uses Verse to implement AI behaviors. You would attach a Verse script to the Character Device or use AI controllers that manage its actions.
- Navigation: For obstacle navigation, UEFN relies on a Navigation Mesh (NavMesh) generated in the level. Verse AI systems can use the NavMesh to find paths around obstacles. You would use functions or components provided by the Verse AI framework to tell the NPC to move to a destination, and the underlying system would handle pathfinding via the NavMesh. The "best techniques" currently available in UEFN for NPC navigation involve setting up a proper NavMesh and utilizing the built-in AI movement and pathfinding capabilities.
- Movement Speed: The movement speed of the NPC would be controlled through properties or functions related to the Character Device or its AI controller in Verse. You would set a low movement speed value to make the character walk slowly.
- Melee Attacks: Implementing melee attacks involves several steps:
- Detection: You would need logic to detect if a target (like the player) is within melee range. This could involve simple distance checks or collision/overlap volumes attached to the NPC.
- Attack Animation: When a target is in range, you would trigger the appropriate melee attack animation that is already set up in your blueprint or animation asset. Verse scripts can communicate with or trigger events on UEFN creative devices and potentially animation systems, though the exact method depends on how your animations are integrated.
- Damage: During a specific frame or point in the attack animation, you would apply damage to the detected target. This might involve calling a function on the target character or using UEFN's damage systems.
- Animation Triggering: Verse can interact with animation states or montages defined for the character. You would use specific Verse functions or events to signal the animation system (which you mentioned is handled in a blueprint or elsewhere) to play the walk cycle (at slow speed) and the melee attack animations.
In summary, creating this NPC in UEFN Verse requires:
- A Character Device as the physical representation.
- A Verse script using UEFN's AI framework to control behavior.
- Utilizing the Navigation Mesh and Verse AI movement functions for pathfinding around obstacles.
- Setting the character's movement speed property to a low value.
- Implementing logic within the Verse script for target detection, triggering melee attack animations, and applying damage.
To write the actual script, you would need to consult the official Epic Games UEFN Verse documentation, API references, and examples, which provide the precise syntax and function calls for these operations. These resources are the only reliable source for accurate, up-to-date Verse code.Based on the search results, here's a breakdown of how you would approach creating such an NPC in UEFN Verse, highlighting the relevant concepts and tools, while reiterating that a complete, error-free script is not feasible without the full UEFN environment and documentation:
Core Concepts and Devices:
- NPC Spawner Device: This is the primary device for bringing customizable NPCs into your UEFN island. It allows control over appearance, behavior, animation, and modifiers[1].
- Character Device: Represents the NPC entity that can be controlled by Verse and can visualize characters and play emotes[2]. You can also use multiple Character Devices with a Character Device Controller to manage groups of NPCs[3].
- Verse AI Module: NPCs in UEFN inherit from the AI module, providing functions for direct control over their state and actions[4].
- Navigatable Interface: This interface, exposed by the AI module, allows you to direct an NPC to navigate to a specific area or target[4][5].
- Navigation Mesh (NavMesh): UEFN uses a NavMesh to enable NPCs to find paths and navigate around obstacles[4][6]. NPCs utilize the NavMesh for pathfinding decisions and update their routes as the environment changes[4].
- Animation Controller Interface: Each Creative prop (including characters) has a
play_animation_controller that allows you to play animations. You can retrieve this interface using GetPlayAnimationController()[7][8]. It provides functions like Play() (synchronous) and PlayAndAwait() (asynchronous) to trigger animations[7].
Implementing the NPC Behavior in Verse:
- Create a Custom NPC Behavior Script: You would create a new Verse file as a custom NPC Behavior[9]. This script will define the NPC's actions.
- Get NPC References: Within the behavior script, you would get a reference to the NPC's agent using
GetAgent[] and then its character interface using GetFortCharacter[]. This gives you access to its gameplay data, including the AI module for navigation and focus[5][9].
- Control Movement Speed: While the search results don't explicitly show a direct "set movement speed" function in Verse, character movement is handled by the
CharacterMovementComponent in Unreal Engine[10][11][12], and Verse interacts with character properties. It's highly probable that you would access and modify a speed-related property through the character or its AI controller interface. Another approach for player speed in Verse involves tracking position changes over time[13][14], but for NPC speed control, directly setting a property is the expected method.
- Navigation and Obstacle Avoidance:
- Utilize the
navigatable interface to command the NPC to move to a target. The underlying NavMesh will handle finding a path and avoiding static obstacles[4][6].
- For dynamic obstacle avoidance (like other characters), Unreal Engine uses systems like Reciprocal Velocity Obstacles (RVO) and Detour Crowd Manager[15]. RVO is included in the
CharacterMovementComponent[15]. While these are primarily mentioned in the context of Unreal Engine's C++ and Blueprint, Verse interfaces for AI likely leverage these systems automatically when using navigation functions, or might expose properties to configure avoidance behavior.
- Melee Attack Logic:
- Target Detection: Implement logic to detect nearby players within a certain range. This could involve distance checks between the NPC's location (
GetTransform().Translation) and player locations[16][17] or using collision volumes.
- Triggering Animations: When a target is in range, use the
play_animation_controller to trigger the melee attack animation from your blueprint[7][8]. You would likely need to expose the animation asset to Verse using asset reflection[7]. The Play() or PlayAndAwait() functions would be used[7]. Note that directly triggering animations from Verse might have limitations or specific methods depending on how the animations are set up in the blueprint[18].
- Applying Damage: At the appropriate point in the animation (e.g., using animation notifies or events), apply damage to the detected target. NPCs implement the interface, allowing them to take damage, and you would need to call a function to apply damage to the target character[4][17].
Animation Integration with Blueprints:
Since your animations are in a blueprint, the Verse script would need to interact with that blueprint. This could involve:
- Exposing Blueprint Functions/Events to Verse: You might expose functions or events in your blueprint that the Verse script can call to trigger specific animations.
- Verse Calling Blueprint Animation Logic: Verse can potentially interact with or trigger events on UEFN creative devices, which might then trigger animation logic within a blueprint associated with that device[19][20]. The
Cinematic Sequence Device can be used to trigger Level Sequences containing animations[19][7].
Important Considerations and Limitations:
- Verse is Evolving: Verse is still under active development, and the available features and best practices are constantly being updated.
- Lack of Direct Blueprint Access in Verse: While Verse can interact with devices and potentially trigger blueprint events, it does not have the same level of direct access to blueprint nodes and logic as C++ or other blueprint scripts.
- Animation Workflow: The most efficient way to trigger animations from Verse when they are defined in a blueprint might require specific setup to expose those animations or trigger mechanisms to the Verse environment[7][18].
- Complex AI Behaviors: For more complex AI (like deciding when to attack, when to move, patrolling, etc.), you would build a state machine or behavior tree within your Verse script, using loops and conditional logic based on the NPC's state and the environment[4][9].
Due to the constraints of not being able to provide actual code without the necessary environment and up-to-date documentation, this explanation focuses on the architectural components and Verse concepts you would use. To write the precise script, you would need to refer to the official Epic Games UEFN documentation and Verse API references.