Virtual object control method and apparatus, electronic device, storage medium, and program product
Patent Information
- Application Number
- CN202510224436.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-26
- Publication Date
- 2026-08-28
AI Technical Summary
[0002]在游戏开发中,智能体的行为控制采用行为树来实现固定行为模式,行为树在实际应用中也面临着诸多挑战,随着游戏复杂度的增加,行为树的规模非常庞大,在处理大量并发路径时,行为树需要频繁地遍历和评估各个节点的状态,降低了智能体行为控制的效率
[0020] In response to a virtual object triggering a target virtual event, a target tree node representing the target virtual event is determined from the behavior tree. In response to the workflow associated with the target tree node and the target virtual event, the workflow is invoked. Following the order of each process node in the workflow, the virtual object is sequentially controlled to execute the sub-events represented by the process nodes. Thus, by invoking the workflow through tree nodes in the behavior tree, the characteristics of the workflow simplify the configuration of tree nodes in the behavior tree, significantly reducing the traversal process for tree nodes in the behavior tree. This reduces complex calculations and resource consumption, improving the efficiency of controlling virtual objects to execute target virtual events. Furthermore, by invoking the workflow of the target virtual event, unified control of different virtual objects can be achieved. Specifically, different virtual objects can be controlled by invoking the same target virtual event's workflow when executing the same virtual event, without needing to configure a separate behavior tree for each virtual object. This improves the universality of behavior tree control over virtual objects, reduces redundant configuration workload, and enhances the maintainability and scalability of the behavior tree.
Smart Images

Figure CN122643686A_ABST
Abstract
Description
Technical Field
[0001] This application relates to computer technology, and more particularly to a virtual object control method, apparatus, electronic device, storage medium, and program product. Background Technology
[0002] In game development, behavior trees are used to control the behavior of intelligent agents to implement fixed behavior patterns. However, behavior trees also face many challenges in practical applications. As the complexity of the game increases, the size of the behavior tree becomes very large. When dealing with a large number of concurrent paths, the behavior tree needs to frequently traverse and evaluate the state of each node, which reduces the efficiency of intelligent agent behavior control. Summary of the Invention
[0003] This application provides a virtual object control method, apparatus, electronic device, storage medium, and program product, which can improve the efficiency of controlling virtual objects to execute target virtual events.
[0004] The technical solution of this application embodiment is implemented as follows:
[0005] This application provides a virtual object control method, the method comprising:
[0006] Obtain the behavior tree of a virtual object in a virtual scene, wherein the behavior tree includes tree nodes for characterizing virtual events that the virtual object can perform;
[0007] In response to the virtual object triggering a target virtual event, a target tree node representing the target virtual event is determined from the behavior tree;
[0008] In response to a workflow associated with the target virtual event for the target tree node, the workflow is invoked, wherein each process node in the workflow represents a sub-event of the target virtual event;
[0009] According to the order of each process node in the workflow, the virtual object is controlled to execute the sub-events represented by the process node in sequence.
[0010] This application provides a virtual object control device, including:
[0011] A data acquisition module is used to acquire the behavior tree of virtual objects in a virtual scene, wherein the behavior tree includes tree nodes for characterizing virtual events that the virtual objects can perform;
[0012] A node selection module is used to determine a target tree node representing the target virtual event from the behavior tree in response to the virtual object triggering a target virtual event;
[0013] An event execution module is used to respond to a workflow in which the target tree node is associated with the target virtual event, and to invoke the workflow, wherein each process node in the workflow represents a sub-event of the target virtual event; and to sequentially control the virtual object to execute the sub-events represented by the process nodes according to the order of each process node in the workflow.
[0014] This application provides an electronic device, including:
[0015] Memory is used to store executable instructions for a computer;
[0016] The processor, when executing computer-executable instructions stored in the memory, implements the virtual object control method provided in the embodiments of this application.
[0017] This application provides a computer-readable storage medium storing a computer program or computer-executable instructions for implementing the virtual object control method provided in this application when executed by a processor.
[0018] This application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, they implement the virtual object control method provided in this application.
[0019] The embodiments of this application have the following beneficial effects:
[0020] In response to a virtual object triggering a target virtual event, a target tree node representing the target virtual event is determined from the behavior tree. In response to the workflow associated with the target tree node and the target virtual event, the workflow is invoked. Following the order of each process node in the workflow, the virtual object is sequentially controlled to execute the sub-events represented by the process nodes. Thus, by invoking the workflow through tree nodes in the behavior tree, the characteristics of the workflow simplify the configuration of tree nodes in the behavior tree, significantly reducing the traversal process for tree nodes in the behavior tree. This reduces complex calculations and resource consumption, improving the efficiency of controlling virtual objects to execute target virtual events. Furthermore, by invoking the workflow of the target virtual event, unified control of different virtual objects can be achieved. Specifically, different virtual objects can be controlled by invoking the same target virtual event's workflow when executing the same virtual event, without needing to configure a separate behavior tree for each virtual object. This improves the universality of behavior tree control over virtual objects, reduces redundant configuration workload, and enhances the maintainability and scalability of the behavior tree. Attached Figure Description
[0021] Figure 1 This is a schematic diagram of the architecture of the virtual object control system provided in an embodiment of this application;
[0022] Figure 2 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application;
[0023] Figure 3 This is a first flowchart illustrating the virtual object control method provided in this application embodiment;
[0024] Figure 4 This is a second flowchart illustrating the virtual object control method provided in the embodiments of this application;
[0025] Figure 5 This is a schematic diagram of behavior tree updating provided in an embodiment of this application;
[0026] Figure 6 This is a third flowchart illustrating the virtual object control method provided in this application embodiment;
[0027] Figure 7 This is a schematic diagram of position adjustment provided in an embodiment of this application;
[0028] Figure 8 This is a schematic diagram of the fourth process of the virtual object control method provided in the embodiments of this application;
[0029] Figure 9 This is a schematic diagram of the behavior tree provided in the embodiments of this application;
[0030] Figure 10 This is a schematic diagram of the workflow construction interface provided in an embodiment of this application;
[0031] Figure 11 This is a schematic diagram of the data structure of the streaming execution event provided in the embodiments of this application;
[0032] Figure 12 This is a schematic diagram of the node structure provided in the embodiments of this application;
[0033] Figure 13 This is a flowchart of the execution events provided in the embodiments of this application;
[0034] Figure 14 This is a schematic diagram of the principle of setting event numbers provided in the embodiments of this application;
[0035] Figure 15 This is a schematic diagram of the first interface of the execution event provided in the embodiments of this application;
[0036] Figure 16 This is a schematic diagram of the second interface of the execution event provided in the embodiments of this application;
[0037] Figure 17 This is a schematic diagram of the third interface of the execution event provided in the embodiments of this application.
[0038] It should be noted that the terms "first" and "second" mentioned above are only used to distinguish between different options and do not represent the degree of superiority or inferiority of the options or their priority in the implementation process. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0040] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0041] In the following description, the terms "first, second, third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0042] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.
[0043] In the implementation of this application, the collection and processing of relevant data should strictly comply with the requirements of relevant national laws and regulations, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of laws and regulations and the authorization of the personal information subject.
[0044] Unless otherwise defined, all technical and scientific terms used in the embodiments of this application have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in the embodiments of this application is for the purpose of describing the embodiments of this application only and is not intended to limit this application.
[0045] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.
[0046] 1) Virtual Scene: A virtual game scene displayed (or provided) by the game program when it runs on the terminal. This virtual scene can be a simulation of the real world, a semi-simulated / semi-fictional virtual environment, or a purely fictional virtual environment. The virtual scene can be any of a two-dimensional, 2.5-dimensional, or three-dimensional virtual scene; this application does not limit the dimension of the virtual scene. For example, a virtual scene may include the sky, land, ocean, etc., and the land may include environmental elements such as deserts and cities. Users can control virtual objects to move within this virtual scene.
[0047] 2) Virtual Objects: These are interactive representations of people and objects within a virtual scene, or movable objects within the virtual scene. These movable objects can be virtual characters, virtual animals, anime characters, etc., such as people or animals displayed in a virtual scene. A virtual object can be a virtual avatar representing the user within the virtual scene. A virtual scene can include multiple virtual objects, each with its own shape and volume, occupying a portion of the space within the virtual scene.
[0048] 3) Behavior Tree: A structure used to model and implement complex behaviors in fields such as game development, robot control, and artificial intelligence. A behavior tree defines the behavioral logic of a virtual object through a tree-like structure of nodes, with each node representing a specific behavior.
[0049] In related technologies, during game development, AI agents in games do not need complex behaviors; they only need to exhibit fixed behavioral patterns. Using behavior trees to execute fixed behavioral patterns not only increases the complexity of program execution but also leads to an ever-growing size of the behavior tree due to implementing too many behavioral patterns in a single tree, posing significant challenges to program operation and debugging. To address these issues, this application provides a virtual object control method, device, electronic device, computer-readable storage medium, and computer program product, improving the efficiency of controlling virtual objects to execute target virtual events.
[0050] The virtual object control method described in this application can be applied to various fields, such as game operation, digital human question and answer, etc. That is, the virtual object control method in this application is not limited to a certain field.
[0051] The following describes exemplary applications of the electronic device provided in the embodiments of this application. The device provided in the embodiments of this application can be implemented as a terminal or as a server. The following will describe exemplary applications when the device is implemented as a server.
[0052] See Figure 1 , Figure 1 This is a schematic diagram of the architecture of the virtual object control system 100 provided in the embodiments of this application. In order to support a virtual object control application, the terminal (terminal 400 is shown as an example) connects to the server 200 through the network 300. The network 300 can be a wide area network or a local area network, or a combination of the two.
[0053] Terminal 400 is used to send the behavior tree of virtual objects in the virtual scene to server 200 via network 300. Server 200 is used to respond to the virtual object triggering a target virtual event, determine the target tree node representing the target virtual event from the behavior tree, the behavior tree includes tree nodes representing virtual events that the virtual object can execute; respond to the workflow associated with the target tree node and the target virtual event, invoke the workflow; according to the order of each process node in the workflow, control the virtual object to execute the sub-events represented by the process node in sequence, and return the sub-events represented by the process node to terminal 400. Terminal 400 displays the sub-events represented by the process node executed by the virtual object through graphical interface 410.
[0054] The following is an example of how terminal 400 controls virtual objects.
[0055] In some embodiments, the terminal 400 can independently complete virtual object control tasks. For example, the terminal 400 is used to obtain the behavior tree of virtual objects in a virtual scene; in response to the virtual object triggering a target virtual event, it determines the target tree node representing the target virtual event from the behavior tree, the behavior tree including tree nodes representing virtual events that the virtual object can execute; in response to the workflow associated with the target tree node and the target virtual event, it invokes the workflow; according to the order of each process node in the workflow, it sequentially controls the virtual object to execute the sub-events represented by the process nodes, and displays the sub-events represented by the process nodes executed by the virtual object through the graphical interface 410.
[0056] In one implementation scenario, the server or terminal can control the virtual pet to interact during game operation, obtain the behavior tree of the virtual pet in the game scene; in response to the virtual pet triggering an interaction event (such as making friends), determine the target tree node representing the interaction event from the behavior tree; in response to the workflow associated with the target tree node and the interaction event, call the workflow; according to the order of each process node in the workflow, control the virtual pet to execute the sub-interaction events represented by the process node in the workflow (such as playing happy animation).
[0057] In one implementation scenario, the server or terminal can control the digital human to respond to questions raised by the user, obtain the behavior tree of the virtual digital human in the virtual scene; in response to the virtual digital human triggering a response event (such as responding to a question raised by the user), determine the target tree node representing the response event from the behavior tree; in response to the workflow associated with the target tree node and the response event, invoke the workflow; according to the order of each process node in the workflow, control the virtual digital human to execute the sub-response events represented by the process nodes in sequence (such as responding to a specific question (such as the settlement of goods)).
[0058] In some embodiments, server 200 may be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
[0059] Terminal 400 can be a smartphone, tablet computer, laptop computer, desktop computer, smart speaker, smartwatch, smart voice interaction device, smart home appliance, vehicle terminal, aircraft, etc., but is not limited to these. The terminal and server can be directly or indirectly connected via wired or wireless communication, which is not limited in this embodiment.
[0060] See Figure 2 , Figure 2 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Figure 2 The electronic device 500 shown can be Figure 1 The terminal 400 or server 200, and the electronic device 500 include: at least one processor 510, memory 550, and at least one network interface 520. The various components in server 200 are coupled together via a bus system 540. It is understood that the bus system 540 is used to implement communication between these components. In addition to a data bus, the bus system 540 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 2 The general labeled all buses as Bus System 540.
[0061] The processor 510 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.
[0062] User interface 530 includes one or more output devices 531 that enable the presentation of media content, including one or more speakers and / or one or more visual displays. User interface 530 also includes one or more input devices 532, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls;
[0063] In some embodiments, when the virtual object control task is independently completed by the terminal 400, the server 200 provided in this application embodiment does not include the user interface 530.
[0064] The memory 550 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state storage, hard disk drives, optical disk drives, etc. The memory 550 may optionally include one or more storage devices physically located away from the processor 510.
[0065] The memory 550 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 550 described in this application embodiment is intended to include any suitable type of memory.
[0066] In some embodiments, memory 550 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.
[0067] Operating system 551 includes system programs for handling various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, driver layer, etc., for implementing various basic business functions and handling hardware-based tasks;
[0068] The network communication module 552 is used to reach other computing devices via one or more (wired or wireless) network interfaces 520, exemplary network interfaces 520 including: Bluetooth, WiFi, and Universal Serial Bus (USB), etc.
[0069] Presentation module 553 is configured to enable the presentation of information (e.g., a user interface for operating peripheral devices and displaying content and information) via one or more output devices 531 (e.g., a display screen, a speaker, etc.) associated with user interface 530;
[0070] In some embodiments, when the virtual object control task is performed independently by the terminal 400, the server 200 provided in this application embodiment may not include the presentation module 553.
[0071] The input processing module 554 is used to detect and translate one or more user inputs or interactions from one or more input devices 532; in some embodiments, when the virtual object control task is performed independently by the terminal 400, the server 200 provided in this application embodiment may not include the presentation module 553.
[0072] In some embodiments, the apparatus provided in this application can be implemented in software. Figure 2 A virtual object control device 555 stored in memory 550 is shown. This device can be software in the form of programs and plug-ins, and includes the following software modules: a data acquisition module 5551, a node selection module 5552, and an event execution module 5553. These modules are logically connected and can therefore be arbitrarily combined or further separated according to the functions they implement. The functions of each module will be described below.
[0073] It should be noted that, in the examples of virtual object control below, those skilled in the art, based on their understanding of the following text, can apply the virtual object control method provided in the embodiments of this application to control virtual objects.
[0074] See Figure 3 , Figure 3 This is a first flowchart illustrating the virtual object control method provided in this application embodiment, which will be combined with... Figure 3 The steps shown will be explained below. The virtual object control method provided in this application embodiment can be implemented by the server or the terminal alone, or by the server and the terminal working together. The following will be an example of the server and the terminal working together.
[0075] In step 101, the behavior tree of the virtual objects in the virtual scene is obtained.
[0076] The behavior tree includes tree nodes that represent the virtual events that a virtual object can execute. It may also include a combiner node connecting two nodes, where the combiner node is the parent node of the two nodes, and the two nodes are the left and right child nodes of the combiner node, respectively. The combiner node executes the left child node first, then the right child node. The behavior tree may also include a decorator node that determines whether to execute the virtual event represented by a node. The decorator node has only one child node and determines whether to execute the virtual event represented by the node based on specific rules.
[0077] The behavior tree's operational logic starts from the root node, progressively searching downwards and executing corresponding tree nodes based on relationships and conditions between nodes. The root node is the top-level node, the starting point and entry point of the entire behavior tree. From the root node, the behavior tree expands downwards according to preset conditions, executing the virtual events represented by each tree node. Tree nodes are the basic units in the behavior tree, representing virtual events that virtual objects can execute. Each tree node can represent a specific virtual event (such as "move," "attack," "wait," etc.). Tree nodes are connected through parent-child relationships, forming a hierarchical structure that defines the order in which virtual objects execute virtual events. This application does not limit the specific form of the behavior tree; it can be a state machine-based behavior tree, a priority-based behavior tree, etc. Virtual events refer to a series of behaviors or interactive actions exhibited by virtual objects in a virtual scene based on preset rules and player actions. These events are the basic elements that constitute the virtual world. They can be dialogues between virtual characters, interactions between characters and the environment, or players' operations on game items. In a virtual scene, the occurrence of virtual events is usually accompanied by certain triggering conditions and rules, which together determine the direction and outcome of the event.
[0078] In some embodiments, see Figure 4 , Figure 4 This is a second flowchart illustrating the virtual object control method provided in this application embodiment, specifically for... Figure 3 Step 101 shown can be achieved through... Figure 4 Steps 1011 to 1013 are implemented, and will be explained in detail below.
[0079] In step 1011, the initial behavior tree of the virtual objects in the virtual scene is obtained, and candidate tree nodes associated with candidate workflows are constructed.
[0080] Here, the initial behavior tree is the behavior tree for virtual objects executing simple virtual events in a virtual scene. The initial behavior tree contains a root node and multiple tree nodes, each representing a virtual event. Candidate tree nodes are nodes added based on the initial behavior tree. Candidate tree nodes are associated with candidate workflows, which are the execution flow for implementing specific virtual events. They decompose complex virtual events into multiple ordered sub-events to progressively complete the virtual events triggered by the virtual object. Each workflow contains multiple consecutive node sets, each containing at least one process node. A node set is a modular unit within the workflow, combining related process nodes. The order between node sets is sequential; that is, all process nodes in one node set are completed before moving to the next, ensuring the orderly execution of virtual events. A process node is the basic unit in a node set, representing the specific sub-event that the virtual object needs to execute. Each process node can represent different virtual events; for example, one process node might represent a virtual object's movement action, while another might represent an attack action. By combining multiple process nodes in a certain order, complex virtual events can be decomposed.
[0081] In some embodiments, the above-mentioned "constructing candidate tree nodes associated with candidate workflows" can be implemented in the following ways: obtaining an initial tree node; constructing a callback function for invoking candidate workflows; assigning a value to the initial tree node based on the callback function, and determining the assigned initial tree node as a candidate tree node.
[0082] Here, a callback function is a function invoked when a specific condition or event is triggered to execute specific logic. This application does not limit the specific implementation of the callback function; it can be a synchronous function, an asynchronous function, an anonymous function, etc. Assignment refers to associating the callback function with the initial tree node, enabling the initial tree node to invoke candidate workflows during execution. This application does not limit the specific implementation of the assignment; it can be done through function pointers, property settings, configuration files, etc.
[0083] In step 1012, tree nodes to be deleted are determined from the initial behavior tree based on the candidate virtual events represented by the candidate workflow.
[0084] Among them, the tree nodes to be deleted are used to represent candidate virtual events that the virtual object can execute.
[0085] In some embodiments, step 1012 can be implemented by traversing the initial behavior tree and performing the following processing for each tree node in the initial behavior tree to determine the virtual event represented by the tree node; when the similarity between the virtual event represented by the tree node and the candidate virtual event is greater than the similarity threshold, the tree node is determined as a tree node to be deleted.
[0086] For example, determine the virtual event represented by the tree node (such as controlling a virtual object to escape from point A to point B); when the similarity between the virtual event represented by the tree node and the candidate virtual event (such as controlling a virtual object to move from point A to point B) is greater than the similarity threshold (such as 0.67), the tree node is determined as a tree node to be deleted.
[0087] Following the above embodiments, the similarity between the virtual event represented by the tree node and the candidate virtual event can be determined in the following way: determine the edit distance (e.g., 2) between the virtual event represented by the tree node (e.g., controlling a virtual object to escape from point A to point B) and the candidate virtual event (e.g., controlling a virtual object to move from point A to point B); determine the maximum length (15) between the length of the virtual event represented by the tree node (e.g., 15) and the length of the candidate virtual event (e.g., 15); and determine the similarity between the virtual event represented by the tree node and the candidate virtual event by taking the ratio of the difference between the maximum length and the edit distance (e.g., 11) to the maximum length (e.g., 0.74).
[0088] It should be noted that edit distance is used to characterize the number of single-character edits (insertion, deletion, or replacement) required to transform a general field into an arbitrary rule field. The number of single-character edits is the minimum number of edits required to transform a general field into an arbitrary rule field. Taking the calculation of the edit distance between the virtual event represented by the tree node (such as controlling a virtual object to escape from point A to point B) and the candidate virtual event (such as controlling a virtual object to move from point A to point B) as an example, there are two replacements in this process. The first replacement is to replace "escape" with "move" in "controlling a virtual object to escape from point A to point B", resulting in "controlling a virtual object to move away from point A to point B". The second replacement is to replace "leave" with "move" in "controlling a virtual object to move away from point A to point B", resulting in "controlling a virtual object to move from point A to point B". Therefore, the edit distance between the virtual event represented by the tree node and the candidate virtual event is 2.
[0089] Following the above embodiments, the above-mentioned "determining the similarity between the virtual event represented by the tree node and the candidate virtual event" can also be implemented in the following way: encoding the virtual event represented by the tree node to obtain a first encoding feature (e.g., [0.14, 0.13, -0.06]); encoding the candidate virtual event to obtain a second encoding feature (e.g., [0.14, 0.13, -0.06, 0.15, 0.03, 0.06]); and determining the similarity between the first encoding feature and the second encoding feature (e.g., 0.85) as the similarity between the virtual event represented by the tree node and the candidate virtual event.
[0090] In step 1013, the initial behavior tree is updated based on the candidate tree nodes and the tree nodes to be deleted, and the updated initial behavior tree is determined as the behavior tree.
[0091] Here, update processing can refer to modifying the initial behavior tree, including adding candidate tree nodes and deleting tree nodes to be deleted.
[0092] In some embodiments, the update process of the initial behavior tree based on candidate tree nodes and tree nodes to be deleted in step 1013 can be implemented in the following way: in the initial behavior tree, the candidate tree nodes are determined as the left child nodes of the parent nodes of the tree nodes to be deleted; the child nodes of the tree nodes to be deleted are determined as the right child nodes of the parent nodes of the tree nodes to be deleted; in the initial behavior tree, the tree nodes to be deleted are deleted.
[0093] See Figure 5 , Figure 5 This is a schematic diagram of behavior tree update provided in an embodiment of this application. The initial behavior tree 501 includes tree node 5011, tree node 5012, and tree node 5013. Tree node 5011 is the parent node of the tree node to be deleted, tree node 5012 is the tree node to be deleted, and tree node 5013 is the child node of the tree node to be deleted. The candidate tree node 502 is determined as the left child node of tree node 5011, and tree node 5013 is determined as the right child node of tree node 5011. Tree node 5012 is deleted to obtain the updated initial behavior tree 503.
[0094] In this embodiment, the updating and optimization of the behavior tree in a virtual scene are implemented. By constructing candidate tree nodes associated with candidate workflows, the behavior tree can be flexibly expanded. Simultaneously, tree nodes to be deleted are identified, redundant tree nodes are removed, and the behavior tree is optimized, avoiding redundant calculations and resource waste, and improving the efficiency of controlling virtual object execution events. Furthermore, by calculating the similarity between the virtual events represented by tree nodes and candidate virtual events, the accuracy of behavior tree updates is improved. At the same time, by constructing a behavior tree with target tree nodes that can invoke workflows, unified control of different virtual objects is achieved. This allows different virtual objects to control their behavior by invoking the same target virtual event workflow when executing the same virtual event, without needing to configure a separate behavior tree for each virtual object. This improves the universality of behavior tree control over virtual objects, reduces the workload of redundant configuration, and enhances the maintainability and scalability of the behavior tree.
[0095] See also Figure 3 In step 102, in response to the virtual object triggering the target virtual event, the target tree node representing the target virtual event is determined from the behavior tree.
[0096] Here, a target virtual event is a specific event triggered by a virtual object in a virtual environment. This application does not limit the target virtual event. The target virtual event can be a character entering a specific area, completing a specific task, or interacting with other characters. The triggering of a target virtual event is usually caused by the state or behavior of a virtual object.
[0097] In some embodiments, step 102 can be implemented in the following way: obtaining the triggering condition for the virtual object to execute the target virtual event; in response to the fulfillment of the triggering condition, querying the condition configuration table based on the triggering condition, wherein the condition configuration table includes the association between different candidate conditions and different candidate tree nodes; when a candidate condition corresponding to the triggering condition is found in the condition configuration table, the queried candidate tree node is determined as the target tree node.
[0098] Here, the triggering condition is a specific condition required for a virtual object to execute a target virtual event, such as a character reaching a certain location, possessing a specific item, or meeting a specific state. The condition configuration table stores the relationships between different candidate conditions and different candidate tree nodes. Candidate conditions are the conditions included in the condition configuration table. Candidate tree nodes are nodes in the behavior tree associated with candidate conditions; each candidate condition corresponds to one or more candidate tree nodes, representing the virtual event to be executed when that candidate condition is met. The target tree node is the tree node that matches the triggering condition and is used to guide the virtual object to execute the target virtual event.
[0099] It should be noted that the condition configuration table is a data structure used to store the relationships between different candidate conditions and different candidate tree nodes. This application embodiment does not limit the condition configuration table. The condition configuration table can be a data structure implemented as a hash table, a data structure implemented as an array, etc., used to quickly perform lookup, insertion, and deletion operations on the correspondence between the composition structure and the category. The hash table uses a hash function to calculate the index value, mapping the composition structure of the input trigger condition in the candidate conditions to the position in the hash table to access the candidate tree node.
[0100] In some embodiments, the above-mentioned "querying candidate conditions corresponding to the triggering condition from the condition configuration table" can be achieved by: traversing the candidate conditions in the condition configuration table; when the similarity between the candidate condition and the triggering condition is greater than the similarity threshold, the candidate condition is determined as the candidate condition corresponding to the triggering condition.
[0101] Following the above embodiments, the step of determining the similarity between candidate conditions and triggering conditions is similar to the step of "determining the similarity between the virtual event represented by the tree node and the candidate virtual event" and will not be repeated here.
[0102] For example, the condition configuration table mapping table includes the following correspondence: Candidate condition 1 "The distance between the character and virtual object A is less than the distance threshold" corresponds to candidate tree node A, and candidate condition 2 "The distance between the character and virtual object A is greater than or equal to the distance threshold" corresponds to candidate tree node B. When a candidate condition (such as candidate condition 1) corresponding to the trigger condition (such as "The distance between the character and virtual object B is less than the distance threshold") is found in the condition configuration table, the candidate tree node (such as candidate tree node A) corresponding to the candidate condition is determined as the target tree node.
[0103] In this embodiment, by combining triggering conditions and a condition configuration table, the behavior requirements of virtual objects are dynamically responded to, rather than relying on fixed, preset behavior logic. Based on the triggering conditions of the virtual object executing the target virtual event, the matching candidate tree node is accurately queried from the condition configuration table, which improves the flexibility of controlling virtual objects. Furthermore, the virtual events executed can be dynamically adjusted according to different triggering conditions, thereby enhancing the adaptability of virtual objects to various situations in virtual scenes.
[0104] In some embodiments, step 102 can also be implemented in the following manner: in response to a virtual object triggering a target virtual event, acquiring a root node from a behavior tree, and acquiring a trigger condition for the virtual object to execute the target virtual event; performing the following processing iteratively for k, where 0<k≤K, k is a sequentially increasing positive integer, and K is the number of child nodes of the root node: acquiring the k-th child node of the root node; when the condition associated with the k-th child node matches the trigger condition, determining the k-th child node as a target tree node and stopping the iteration; when the condition associated with the k-th child node does not match the trigger condition, acquiring the (k+1)-th child node of the root node.
[0105] Herein, iteration is a process of repeatedly executing a series of operations. The "iteration for k" herein means that k starts from 1, increases sequentially as a positive integer, executes specific processing with the value of k each time, and continues until k reaches K. The embodiments of the present application explicitly define the specific range of iteration times (determined by K), k shall satisfy that it is greater than 0 and less than or equal to K, and k increases by 1 sequentially in each iteration. For example, k may start from 1 and sequentially become 2, 3, etc. until reaching K. The root node of a behavior tree is the topmost node in the behavior tree structure, and is the starting point and entry of the entire behavior tree. The root node is used to characterize the initial behavior state of the virtual object. Starting from the root node, the behavior tree will gradually expand downward according to preset logic and conditions, and execute the behaviors characterized by each child node. A trigger condition is a precondition that needs to be satisfied for a virtual object to execute a target virtual event. The embodiments of the present application impose no limitation on the specific form of the trigger condition, and the trigger condition may be a logical expression, a state judgment, a time condition, etc. The k-th child node is the k-th direct lower-level node of the root node, and is used to represent a specific behavior in the behavior tree. Taking the number of k being 2 as an example for description, the first child node is the left child node of the root node, and the second child node of the root node is the right child node of the root node. The embodiments of the present application impose no limitation on the traversal mode of child nodes, and the traversal mode of child nodes may be traversing the left child node of the root node first, and then traversing the right child node of the root node. Condition matching refers to comparing the condition associated with the k-th child node with the trigger condition to determine whether the k-th child node satisfies the execution condition. The embodiments of the present application impose no limitation on the specific implementation manner of condition matching, and condition matching may be exact matching, partial matching, fuzzy matching, etc. A target tree node is a node finally determined to be executed in the behavior tree, and is used to represent a specific behavior that the virtual object needs to execute.
[0106] In some embodiments, the step of determining "the condition associated with the k-th child node matches the trigger condition" can be implemented in the following manner: determining the similarity between the condition associated with the k-th child node and the trigger condition, and when the similarity is greater than a similarity threshold, the condition associated with the k-th child node matches the trigger condition.
[0107] Following the above embodiments, the steps of "determining the similarity between the condition associated with the kth child node and the triggering condition" are similar to those of "determining the similarity between the virtual event represented by the tree node and the candidate virtual event", and will not be repeated here.
[0108] For example, the root node is obtained from the behavior tree, and the trigger condition for the virtual object to execute the target virtual event "engage in combat" is "player exists and distance is less than 10 meters". Starting from the root node, the child nodes of the root node are traversed sequentially. When the first child node is traversed, its associated condition is "player exists and distance is less than 10 meters". Since the two are a perfect match (both are "enemy exists and distance is less than 10 meters"), the first child node is determined as the target tree node. The trigger condition for the virtual object to execute the target virtual event "restore health" is "health value is less than 30%". Since the associated condition of the first child node does not match the trigger condition, the process continues to the second child node. The associated condition of the second child node is "health value is less than 30%". Since the two are a perfect match (both are "health value is less than 30%)", the second child node is determined as the target tree node, and the iteration stops.
[0109] In some embodiments, the above-mentioned "obtaining the k+1th child node of the root node" can be implemented in the following way: jump from the kth child node of the root node to the root node, and jump from the root node to the k+1th child node of the root node in the order of the child nodes.
[0110] For example, when traversing the kth child node (assuming k=1), but because the association condition of the 1st child node does not match the trigger condition, jump back to the root node and continue traversing the (k+1)th child node.
[0111] In this embodiment, starting from the root node of the behavior tree, each child node is traversed sequentially, and the association conditions of the child nodes are checked against the triggering conditions to quickly locate the tree node corresponding to the target virtual event. Utilizing the hierarchical structure of the behavior tree avoids complex searches of the entire behavior tree, improving the efficiency of controlling virtual object execution events. Simultaneously, the similarity judgment mechanism flexibly handles cases where conditions do not perfectly match. Furthermore, by jumping from the k-th child node of the root node to the root node, and then jumping from the root node to the (k+1)-th child node of the root node according to the order of the child nodes, the need to re-determine whether to jump to the k-th child node according to the execution logic of the behavior tree is avoided, optimizing the traversal process and improving the operational efficiency of virtual object control.
[0112] In step 103, in response to a workflow associated with a target virtual event for a target tree node, a workflow is invoked, wherein each process node in the workflow represents a sub-event of the target virtual event.
[0113] Here, a sub-event is a component of the target virtual event and is used to represent the specific execution behavior of the target virtual event. This application embodiment does not limit the type of sub-events; sub-events can be state updates, resource loading, interactive responses, etc.
[0114] In some embodiments, a start execution function is configured for the target tree node. Step 103 can be implemented in the following way: execute the start execution function; in response to reading the target event identifier used to call the workflow during the execution of the start execution function, query the workflow configuration table based on the target event identifier, wherein the workflow configuration table contains the correspondence between different event identifiers and different candidate workflows; determine the candidate workflow corresponding to the target event identifier as the workflow of the target virtual event, and call the workflow of the target virtual event.
[0115] Here, the start execution function is the first function called before executing the target virtual event represented by the target tree node. The start execution function determines the execution method of the target virtual event (either by calling an external workflow or by using built-in code logic to implement the target virtual event). When the start execution function is executed, the system controls the virtual object to execute the target virtual event represented by the target tree node according to the pre-written code logic. The start execution function includes a callback function configured with a time variable. When the start execution function is executed, the current timestamp is assigned to the time variable. If, after an interruption, the execution of the target virtual event represented by the target tree node is interrupted, and the time variable in the start execution function is not empty, the start execution function exits and the continue execution function is executed. This application embodiment does not limit the start execution function; it can be a function used to start a specific function. The target event identifier is a unique identifier used to mark virtual events executed according to a workflow. This application embodiment does not limit the form and content of the target event identifier; it can be a number, a string, etc. Candidate workflows are workflows that may be executed and correspond to specific event identifiers. In the workflow configuration table, each event identifier is associated with a candidate workflow.
[0116] It should be noted that when a target event identifier for invoking a workflow is read during the execution of the start function, it indicates that the target tree node is associated with a workflow. The virtual object needs to be controlled to execute the target virtual event according to the workflow. Therefore, the workflow configuration table is queried based on the target event identifier, and the candidate workflow corresponding to the queried target event identifier is invoked. When no target event identifier for invoking a workflow is read during the execution of the start function, it indicates that the target tree node is not associated with a workflow. The specific code logic needs to be executed according to the characteristics of the original tree node of the behavior tree, that is, the specific code logic representing the target virtual event built into the start function is executed.
[0117] Taking a movement event from point A to point B (i.e., a target virtual event) as an example, when the target tree node representing the movement event is not associated with a workflow, the specific code logic for the movement event needs to be developed within the start execution function corresponding to the target tree node. This specific code logic includes a coordinate extraction function to extract the coordinates of points A and B, a speed extraction function to obtain the movement speed, and a movement function to execute the movement logic. When the target tree node representing the movement event is associated with a workflow, it is not necessary to develop the specific code logic for the movement event within the start execution function corresponding to the target tree node. Instead, an event identifier marking the workflow corresponding to the movement event can be set within the start execution function of the target tree node. The workflow corresponding to the movement event can be called externally through the event identifier. Therefore, by associating workflows with tree nodes, the development resources required for the original tree nodes can be greatly reduced, improving development efficiency.
[0118] Following the above embodiments, a start execution interface is configured for the target tree node. The above "execute start execution function" can be implemented in the following way: call the start execution function through the start configuration interface.
[0119] Following the above embodiments, the above-mentioned "determining the candidate workflow corresponding to the target event identifier as the workflow of the target virtual event" can also be implemented in the following way: when a virtual event identifier associated with the target virtual event identifier is found in the workflow configuration table, the candidate workflow corresponding to the found virtual event identifier is determined as the workflow of the target virtual event.
[0120] Here, the workflow configuration table is a data structure used to store the correspondence between different event identifiers and different candidate workflows. This application embodiment does not limit the specific implementation of the workflow configuration table; it can be a table, database, configuration file, etc. The correspondence refers to the mapping relationship between event identifiers and candidate workflows, used to determine the specific workflow to be executed for a given virtual event. This application embodiment does not limit the specific form of the correspondence; it can be one-to-one, one-to-many, many-to-one, etc. Querying refers to searching the workflow configuration table for virtual event identifiers associated with the target virtual event identifier and the corresponding candidate workflows. This application embodiment does not limit the specific implementation of the query; it can be exact matching, fuzzy matching, range matching, etc.
[0121] It should be noted that the data structure of the workflow configuration table is similar to that of the condition configuration table, and will not be elaborated here.
[0122] In some embodiments, the steps of "querying the workflow configuration table based on the target event identifier" are similar to the steps of "querying the candidate conditions corresponding to the triggering conditions from the condition configuration table", and will not be repeated here.
[0123] In this embodiment, querying the workflow associated with the target virtual event from the workflow configuration table enables quick and accurate determination of the workflow to be executed for the target virtual event, thereby improving the efficiency and accuracy of virtual object control. Simultaneously, querying the workflow configuration table through the target event identifier allows different virtual objects to execute the corresponding target virtual event based on the identifier, eliminating the need to configure a separate behavior tree for each virtual object. This enhances the universality of behavior tree control over virtual objects, reduces repetitive configuration workload, and improves the maintainability and scalability of the behavior tree. Furthermore, compared to code that can call the start execution function of the target tree node in the workflow, code that cannot call the start execution function of the target tree node in the workflow is more complex. By introducing a target tree node that can call the workflow, the structure of the behavior tree is optimized, reducing the space occupied by the behavior tree and the development resources required.
[0124] In step 104, the virtual objects are sequentially controlled to execute the sub-events represented by the process nodes according to the order of each process node in the workflow.
[0125] It should be noted that process nodes in different node sets are executed sequentially in a fixed order. Process nodes in the next node set can only begin execution after the process nodes in the previous node set have finished executing. Process nodes in the same node set are executed according to their execution mode, which can be parallel execution, random execution, etc.
[0126] In some embodiments, the start execution function includes a callback function, and the workflow comprises multiple consecutive sets of nodes, each set containing at least one process node. See [link to documentation]. Figure 6 , Figure 6 This is a third flowchart illustrating the virtual object control method provided in this application embodiment, specifically for... Figure 3 Step 104 shown can be achieved through... Figure 6 Steps 1041 to 1042 are implemented, and will be explained in detail below.
[0127] In step 1041, in response to the callback function representing the target virtual event represented by the target tree node being executed for the first time, the virtual object is controlled to execute the sub-event represented by the process node in the i-th node set in the virtual scene.
[0128] Here, the callback function is passed as an argument to another function. When a specific event occurs, the called function invokes the callback function, which is used to convey information about the execution status of the target virtual event.
[0129] It should be noted that the callback function is configured with a time variable. When the time variable is empty, the callback function represents the initial execution of the target virtual event represented by the target tree node. When the time variable is not empty, the callback function represents the target virtual event represented by the target tree node that is not being executed for the first time and has not yet been completed. It controls the virtual object to execute the sub-events represented by the process nodes in the i-th node set within the virtual scene until the sub-events are fully executed.
[0130] In some embodiments, execution modes and node types are set for process nodes. The step 1041 of controlling the virtual object to execute the sub-event represented by the process node in the i-th node set in the virtual scene can be implemented in the following way: based on the execution mode of the process node in the i-th node set, the process nodes in the i-th node set are divided into a parallel execution set or a random execution set. The parallel execution set contains process nodes in the i-th node set used for parallel execution, and the random execution set contains process nodes in the i-th node set used for random execution. Candidate process nodes are selected from the random execution set, and the target process node is determined to be at least one of the following: a candidate process node, a process node in the parallel execution set. The target node type of the target process node is obtained, and the virtual object is controlled to execute the sub-event associated with the target node type in the virtual scene.
[0131] Here, node type is used to distinguish process nodes with different properties or functions, and different types of process nodes correspond to different sub-events. This application embodiment does not limit the node type; the node type can be movement, playing animation, etc. The target node type is the type possessed by the target process node. By obtaining the target node type, the sub-event represented by the target process node can be clearly identified. The i-th node set is a set containing at least one process node. The parallel execution set is used to store process nodes in the i-th node set that can be executed simultaneously. This application embodiment does not limit the parallel execution set; process nodes in the parallel execution set can be process nodes with the same priority and no mutual dependencies. The random execution set contains process nodes in the i-th node set whose execution order is random. This application embodiment does not limit the random execution set; process nodes in the random execution set can be process nodes that cannot be executed simultaneously (for example, process node A represents the sub-event of raising hands, and process node B represents the sub-event of lowering hands; only one sub-event can be selected from process node A and process node B for execution, therefore, the execution mode of process node A and process node B is random execution). Candidate process nodes are process nodes selected from the random execution set.
[0132] For example, in the i-th node set, process node A is executed in parallel, process node B is executed in parallel, process node C is executed in random, and process node D is executed in random. The process nodes in the i-th node set are divided into a parallel execution set or a random execution set. The parallel execution set includes process node A and process node B, and the random execution set includes process node C and process node D. Candidate process nodes (such as process node C) are selected from the random execution set, and the target process node is determined to be at least one of the following: candidate process node (such as process node C) or process node in the parallel execution set (such as process node A and process node B).
[0133] In some embodiments, the above-mentioned "controlling the virtual object to execute sub-events associated with the target node type in the virtual scene" can be achieved in the following ways: determining the execution parameters of the sub-events; controlling the virtual object according to the execution parameters at each time point to obtain the action of the virtual object at each time point; and controlling the virtual object to execute each action.
[0134] For example, let's take the rotation angle of the virtual object's arm as the execution parameter. By controlling the rotation angle of the virtual object's arm at the execution time point, we can obtain the action corresponding to the time point. At time t = 0 seconds, the action is to adjust the rotation axis angle of the virtual object's arm to 0 degrees. At time t = 1 second, the action is to adjust the rotation axis angle of the virtual object's arm to 90 degrees.
[0135] In the embodiments of the present application, process nodes in a node set are divided into a parallel execution set and a random execution set, and the behavior of a virtual object is flexibly scheduled according to the execution modes of the process nodes. The process nodes in the parallel execution set can be executed simultaneously, which improves the efficiency of behavior execution, while the process nodes in the random execution set increase the diversity and randomness of behaviors, and improve the authenticity of the behaviors of the virtual object. In addition, by determining execution parameters of an executed sub-event and controlling the virtual object according to the execution parameters at each time point, the action execution of the virtual object is accurately implemented, which enhances the adaptability and interactivity of the virtual object to a virtual scene.
[0136] In step 1042, in response to that sub-events represented by process nodes in the i-th node set are all executed by the virtual object, the virtual object is controlled to execute sub-events represented by process nodes in the (i+1)-th node set in the virtual scene, wherein 0 < i < I, i is a sequentially increasing positive integer, and I is the number of multiple node sets.
[0137] In some embodiments, the above step of "controlling the virtual object to execute the sub-events represented by the process nodes in the (i+1)-th node set in the virtual scene" is similar to the above step of "controlling the virtual object to execute the sub-events represented by the process nodes in the i-th node set in the virtual scene", and will not be repeated herein.
[0138] With the embodiments of the present application, a complex virtual event is decomposed into multiple ordered sub-events, and the virtual event triggered by the virtual object is completed step by step. After all process nodes in one node set are executed, the process automatically flows to the next node set, which ensures the ordered execution of the virtual event.
[0139] In some embodiments, a start execution function includes a callback function, and step 104 can also be implemented in the following manner: in response to that the callback function indicates that a target virtual event represented by a target tree node has not been executed completely, a continue execution function configured for the target tree node is executed; in response to that a target process node corresponding to an interrupted sub-event is read during execution of the continue execution function, the virtual object is controlled to continue executing the sub-event represented by the target process node in the virtual scene.
[0140] Here, the resume execution function is a function that, after the virtual event represented by the target tree node is interrupted, resumes the execution of the interrupted virtual event, used to restart the execution of the virtual event represented by the interrupted target tree node. When the resume execution function is executed, the subsequent operation process continues according to its internal logic. An interrupted sub-event is a sub-event whose execution is paused for some reason during execution. These sub-events retain their execution progress during interruption so that execution can be resumed later. This application embodiment does not limit the interrupted sub-events; the interruption reason can be insufficient resources, external signal interference, etc.
[0141] It should be noted that if, before executing the continue execution function, during the execution of the start execution function, a target event identifier used to invoke the workflow is read and the callback function in the start execution function indicates that the target virtual event represented by the target tree node has not been fully executed, it means that the target tree node is associated with a workflow. The virtual object needs to be controlled to execute the target virtual event according to the workflow. Therefore, the execution jumps to the interrupted process node in the workflow associated with the target event identifier and continues to execute the sub-event represented by the interrupted process node. Conversely, if, before executing the continue execution function, during the execution of the start execution function, a target event identifier used to invoke the workflow is not read and the callback function in the start execution function indicates that the target virtual event represented by the target tree node has not been fully executed, it means that the target tree node is not associated with a workflow. The specific code logic needs to be executed according to the characteristics of the original tree node of the behavior tree, that is, the specific code logic representing the target virtual event built into the continue execution function.
[0142] Taking a movement event from point A to point B (i.e., a target virtual event) as an example, when the target tree node representing the movement event is not associated with a workflow, the specific code logic for the movement event needs to be developed within the start execution function corresponding to the target tree node. This specific code logic includes a coordinate extraction function to extract the coordinates of point B, a speed extraction function to obtain the movement speed, an object coordinate extraction function to extract the position of the virtual object when interrupted, and a movement function to execute the movement logic. When the target tree node representing the movement event is associated with a workflow, it is not necessary to develop the specific code logic for the movement event within the start execution function corresponding to the target tree node. Instead, an event identifier marking the workflow corresponding to the movement event can be set within the start execution function of the target tree node. The workflow corresponding to the movement event can then be called externally through the event identifier. The interrupted process node in the workflow corresponding to the movement event can be set within the continuation execution function of the target tree node. Therefore, by associating the interrupted process node in the workflow with the tree node, the development resources for the original tree node can be greatly reduced, improving development efficiency. 。
[0143] In response to that all the sub-events represented by the target process node have been executed by the virtual object, controlling the virtual object to execute the sub-events represented by other process nodes in the node set where the target process node is located in the virtual scene, and when all the sub-events represented by the process nodes in the node set where the target process node is located have been executed by the virtual object, controlling the virtual object to execute the sub-events represented by the process nodes in the next node set in the virtual scene, wherein other process nodes are process nodes in the node set where the target process node is located except the target process node and the process nodes that have been executed by the virtual object. When all the sub-events represented by the process nodes in all node sets have been executed, calling the end execution function of the target tree node, and exiting the execution of the sub-event represented by the target tree node.
[0144] In some embodiments, a continue execution interface is configured for the target tree node, and the above "executing the continue execution function" can be implemented in the following manner: calling the continue execution function through the continue configuration interface.
[0145] Following the above embodiment, an end execution interface is configured for the target tree node, and the above "calling the end execution function of the target tree node and exiting the execution of the sub-event represented by the target tree node" can be implemented in the following manner: calling the end execution function through the end execution interface, and exiting the execution of the sub-event represented by the target tree node.
[0146] In some embodiments, before the above "reading the target process node corresponding to the interrupted sub-event", for the j-th process node in the i-th node set, in response to that the sub-event represented by the j-th process node has not been completely executed by the virtual object, determining the j-th process node in the i-th node set as the target process node corresponding to the interrupted sub-event, and writing the target process node corresponding to the interrupted sub-event into the continue execution interface, where 0<j≤J, j is a positive integer, and J is the number of process nodes in the i-th node set.
[0147] Following the above embodiment, the above "controlling the virtual object to continue executing the sub-event represented by the target process node in the virtual scene" can be implemented in the following manner: determining the execution progress when the sub-event represented by the target process node is interrupted, and based on the execution progress, controlling the virtual object to continue executing the sub-event represented by the target process node in the virtual scene.
[0148] Here, the execution progress is used to represent the degree of completion of the sub-event when it is interrupted. The embodiments of the present application impose no limitation on the execution progress, and the representation manner of the execution progress may be a percentage of the executed time of the sub-event in the total execution time required for executing the sub-event, or the executed time of the sub-event, etc. Continuing execution means that based on the previous interruption of the execution of the sub-event, the virtual object continues to complete the remaining part of the sub-event represented by the target process node from the position indicated by the execution progress.
[0149] It should be noted that the sub-event represented by the target process node not being executed by the virtual object is used to represent that the sub-event has not reached the completion state during the execution process. This application embodiment does not limit the situation of not being executed. The situation of not being executed can be that the user exits the virtual environment, the virtual object responds to triggering other virtual events, interrupts the execution of the current event, etc., where other virtual events are virtual events other than the sub-event represented by the target process node.
[0150] Following the above embodiments, the above-mentioned "determining the execution progress when the sub-event represented by the target process node is interrupted" can be implemented in the following way: obtaining the first timestamp when the sub-event represented by the target process node is interrupted, and obtaining the second timestamp when the execution of the sub-event represented by the target process node begins; determining the difference between the first timestamp and the second timestamp as the execution duration of the sub-event represented by the target process node; and determining the execution progress when the sub-event represented by the target process node is interrupted based on the execution duration.
[0151] Here, the first timestamp is the time point recorded at the moment when the sub-event represented by the target process node is interrupted. This embodiment does not limit the first timestamp; it can be obtained by a clock mechanism or a specific timing tool. The second timestamp is used to represent the time point at which the execution of the sub-event represented by the target process node begins. The execution duration is the difference between the first and second timestamps, representing the length of time the sub-event takes from the start of execution to its interruption. This embodiment does not limit the execution duration; the unit of execution duration can be seconds, minutes, etc.
[0152] In some embodiments, the above-mentioned "determining the execution progress when the sub-event represented by the target process node is interrupted based on the execution duration" can be implemented in the following ways: determining the total execution time of the sub-event represented by the target process node, and determining the ratio of the execution duration to the total execution time as the execution progress when the sub-event represented by the target process node is interrupted; or, determining the execution duration as the execution progress when the sub-event represented by the target process node is interrupted.
[0153] Here, the total execution time is the total time required for the sub-event represented by the target process node to be fully executed, and is used to represent the duration required for the entire execution of the sub-event.
[0154] For example, the first timestamp when the sub-event is interrupted is 0600, where 0600 indicates that the sub-event was interrupted at 6 hours and 0 minutes. The second timestamp when the sub-event represented by the target process node starts execution is 0556, where 0550 indicates that the sub-event started execution at 5 hours and 56 minutes. The difference between the first and second timestamps (e.g., 4 minutes) is determined as the execution duration of the sub-event represented by the target process node. The total execution time of the sub-event represented by the target process node is determined (e.g., 5 minutes). The ratio of the execution duration (e.g., 4 minutes) to the total execution time (e.g., 5 minutes) (e.g., 0.8) is determined as the execution progress of the sub-event represented by the target process node when it was interrupted; or, the execution duration (e.g., 4 minutes) is determined as the execution progress of the sub-event represented by the target process node when it was interrupted.
[0155] Through the embodiments of this application, the first timestamp when a sub-event is interrupted and the second timestamp when it starts execution are recorded, so as to accurately quantify the execution progress of the sub-event.
[0156] In some embodiments, the above-mentioned "controlling the virtual object to continue executing the sub-event represented by the target process node in the virtual scene" can also be implemented in the following ways: determining the historical pose of the virtual object when the sub-event represented by the target process node is interrupted; determining the current pose of the virtual object in the virtual scene when the target virtual event is triggered; controlling the virtual object to adjust from the current pose to the historical pose and continue executing the sub-event represented by the target process node.
[0157] Here, the historical pose refers to the position and orientation information of the virtual object in the virtual scene when the sub-event represented by the target process node is interrupted. The position information describes the coordinates of the virtual object in the virtual scene, and the orientation information is used to represent the direction, angle, or orientation state of the virtual object. This application embodiment does not limit the orientation information; the orientation information can be Euler angles, quaternions, etc. Euler angles describe the orientation of the object through three rotation angles around different coordinate axes: the x-axis, y-axis, and z-axis, with each axis corresponding to a rotation angle. Quaternions consist of one real part and three imaginary parts, and describe the orientation of the virtual object through specific operational rules. The current pose is the instantaneous position and orientation information of the virtual object in the virtual scene when the target virtual event is triggered. Controlling the virtual object to adjust from the current pose to the historical pose means changing the virtual object's position and orientation in the virtual scene, from the current pose when the target virtual event is triggered to the historical pose at the time of execution progress. This application embodiment does not limit the adjustment method; the adjustment method can be smooth movement, instantaneous switching, etc.
[0158] See Figure 7 , Figure 7 This is a schematic diagram of position adjustment provided in an embodiment of this application. Figure 7In the virtual scene 701 shown, position 703 is the historical position of the virtual object when the sub-event represented by the target process node is interrupted, and position 702 is the current position of the virtual object in the virtual scene 701 when the target virtual event is triggered. The virtual object is controlled to move from position 702 to position 703.
[0159] Following the above embodiments, the step of "controlling the virtual object to continue executing the sub-event represented by the target process node in the virtual scene" is similar to the step of "controlling the virtual object to execute the sub-event represented by the process node in the i-th node set in the virtual scene", and will not be repeated here.
[0160] Through the embodiments of this application, when the execution of a virtual object's sub-event is interrupted and then resumed, the virtual object is accurately adjusted from its current pose to its historical pose, ensuring that the virtual object can return to its previous state upon resumption of execution, thus guaranteeing the continuity and consistency of behavior. Through the mechanism of callback functions and continuation functions, the execution status of the target virtual event is identified in real time, and execution is resumed from the interruption point. This improves the robustness and reliability of the system, as well as execution efficiency and resource utilization, while ensuring the continuity and consistency of virtual object behavior. Furthermore, compared to the code logic of continuation functions that can call the target tree nodes of the workflow, which are more complex, the introduction of target tree nodes that can call the workflow optimizes the structure of the behavior tree, reducing the space occupied by the behavior tree and the development resources required for it.
[0161] In some embodiments, see Figure 8 , Figure 8 This is a schematic diagram of the fourth process of the virtual object control method provided in this application embodiment, in step... Figure 3 After showing 104, execute Figure 8 Steps 201 to 202 are explained in detail below.
[0162] In step 201, the execution mode of the target virtual event is obtained.
[0163] Here, the execution mode refers to the way the target virtual event is executed in the virtual scene. The execution mode can be one of the following modes: cyclic execution, single execution, etc. Cyclic execution means that the target virtual event will be repeatedly executed in the virtual scene according to the set rules. That is, after one execution is completed, the next execution will begin. This application embodiment does not restrict cyclic execution. The conditions for cyclic execution can be preset specific conditions (such as a fixed time for the cycle) or a fixed number of cycles. Single execution is used to characterize that the target virtual event is executed only once in the virtual scene. That is, after the execution is completed, it will not be automatically executed again unless the target virtual event is triggered again.
[0164] In some embodiments, when the execution mode characterizes the cyclic execution of the target virtual event, step 202 is executed cyclically until the loop termination condition is met.
[0165] In step 202, the target tree node representing the target virtual event is determined from the behavior tree. In response to the workflow associated with the target virtual event, the workflow is invoked, and the virtual objects are sequentially controlled to execute the sub-events represented by the process nodes in the virtual scene according to the order of each process node in the workflow.
[0166] It should be noted that the operation of step 202 stops when the loop termination condition is met. This embodiment of the application does not impose restrictions on the loop termination condition; the loop termination condition can be a specific number of executions, execution duration, etc.
[0167] In some embodiments, step 202 is executed repeatedly until the loop termination condition is met, which can be achieved in at least one of the following ways: when the execution duration of the target virtual event (e.g., 5 minutes) is greater than the preset execution duration (e.g., 4 minutes), the loop ends; when the number of times the target virtual event is executed (e.g., 5) is greater than the preset number of times it is executed (e.g., 4), the loop ends; the execution resource amount of the target virtual event (e.g., 5GB) is obtained, and the sum of the execution resource amounts of the target virtual event in the current M executions (taking M as 3 as an example, the sum of the execution resource amounts of the target virtual event in the first 3 executions is 15GB) is greater than the available resource amount (e.g., 12GB), the loop ends, where M is a positive integer less than or equal to N, and N is the number of times the target virtual event is executed.
[0168] It should be noted that the execution duration is the total time spent executing the target virtual event multiple times. The number of executions indicates the number of times the target virtual event is executed. The execution resource quantity is the amount of resources required to execute the target virtual event. This application embodiment does not impose a limit on the execution resource quantity, which can be computing resources, memory resources, etc. The available resource quantity represents the total amount of resources in the system that can currently be used to execute the target virtual event. The loop ends when the sum of the execution resource quantities for the current M executions of the target virtual event exceeds the available resource quantity.
[0169] In some embodiments, step 202 is similar to steps 102 to 104, and will not be described again here.
[0170] In this embodiment, the loop is dynamically terminated based on various conditions, such as execution time, number of executions, or resource consumption, which effectively avoids excessive resource consumption or infinite loops and ensures the stability of the system and the rational use of resources.
[0171] The following will describe an exemplary application of the virtual object control method provided in this application embodiment in a real-world application scenario.
[0172] The embodiments of this application can be applied to various virtual scenarios, such as virtual game scenarios, and can simulate the real interaction process between virtual objects. The following description uses a game as an example.
[0173] In related technologies, during game development, AI agents in games do not need complex behaviors; they only need to exhibit fixed behavioral patterns. Using behavior trees to execute fixed behavioral patterns not only increases the complexity of program execution, but also, due to the implementation of behavior trees, implementing too many behavioral patterns in a single behavior tree leads to an increasingly large behavior tree, posing significant challenges to program operation and debugging.
[0174] To address the aforementioned issues, this application proposes a virtual object control method. This method executes agent behavior based on a behavior tree combined with a streaming execution workflow. Through simple operations via an interactive interface, a streaming execution workflow for an agent (i.e., the aforementioned virtual object) is configured. The original behavior tree execution method is retained, and the workflow is combined with the behavior tree, allowing the agent to switch between behavior tree execution and streaming execution. For example, when the agent is not in combat, its behavior mode is streaming execution; after entering combat, it runs the configured combat behavior tree, switching to behavior tree execution mode. This reduces the content footprint of the behavior tree and improves the flexibility of the agent switching between behavior tree execution and streaming execution.
[0175] For example, see virtual object control. Figure 9 , Figure 9 This is a diagram illustrating the behavior tree principle provided in an embodiment of this application. Figure 9 This includes multiple nodes of a behavior tree used for agent behavior control in this application embodiment, such as root node 901, combiner node 902, condition node 903 (i.e., the decorator node mentioned above), streaming execution node 904, condition node 905, and behavior tree execution node 906. A behavior tree is a structured tool commonly used in game development, artificial intelligence, and robot control to manage complex decision logic and behavior sequences. The multiple nodes of the behavior tree provided in this application embodiment will be explained below.
[0176] The root node 901 is the starting point of the entire behavior tree. It is the parent node of all other nodes and is used to initialize the process or define the entry point of the entire system. Root node 901 records the behavior tree name and node statistics, including the total number of nodes (e.g., 4060), the number of task nodes (e.g., 2), the number of service nodes (e.g., 0), the number of decorator nodes (e.g., 1), the number of combiner nodes (e.g., 1), and the number of subtree nodes (e.g., 4057). The total number of nodes represents the scale of the behavior tree. Task nodes are typically used to execute specific actions or behaviors. In the behavior tree, task nodes are the nodes that actually perform the work, such as "attack the player" or "move to the target location." Task nodes include the streaming execution node 904 and the behavior tree execution node 906 (i.e., the tree nodes mentioned above). Service nodes provide continuous services or updates during the execution of the behavior tree. For example, periodically checking the environment status or updating certain data. Decorator nodes modify the behavior of the child nodes of the decorator node. A decorator node has only one child node and changes the execution logic or return value of that child node through specific rules. For example, limiting the number of executions and reversing return values are examples of behavior tree decorator nodes 903 and 905. Condition node 903 determines whether to execute its child node (i.e., streaming execution node 904) based on the key value in the centralized data storage structure, and condition node 905 determines whether to execute its child node (i.e., behavior tree execution node 906) based on the key value in the centralized data storage structure. Combiner node 902 is used to combine the behaviors of multiple child nodes. A combiner node has multiple child nodes and executes them according to preset rules (such as sequence, selection, etc.). Examples include sequence nodes and selector nodes. Subtree nodes are used to decompose complex behavioral logic into multiple subtrees. Each subtree can be managed independently, and a subtree node can contain multiple child nodes, forming a more complex nested structure. In this behavior tree, most nodes are subtree nodes, resulting in a complex structure used to implement highly complex behavioral logic.
[0177] Combiner node 902 is used to connect different nodes to ensure the continuity of the process. In the behavior tree, combiner node 902 is used to execute the behavior logic of the left subtree first, and then execute the behavior logic of the right subtree. Combiner node 902 connects the left subtree and the right subtree. The left subtree contains condition node 903 and streaming execution node 904, and the right subtree contains behavior tree execution node 906. The root node 901 is the parent node of combiner node 902.
[0178] Condition node 903 is used to determine the direction of subsequent nodes based on the preset centralized data storage structure. When it is determined by condition node 903 that there is an event number corresponding to the event in the data storage structure and the current agent is not in combat (i.e., the condition associated with the kth child node mentioned above), the streaming execution node 904 (i.e. the target tree node) is executed. Among them, combiner node 902 is the parent node of condition node 903.
[0179] The streaming execution node 904 is used to process streaming data or execute continuous processes. The streaming execution node records event numbers, calls the workflow associated with the event number through a callback function, and executes the workflow.
[0180] See Figure 10 , Figure 10 This is a schematic diagram of the workflow construction interface provided in the embodiments of this application. The following is a description of... Figure 10 The workflow building interface is described in detail.
[0181] The event module switching button 1001 is used to distinguish which module an event belongs to, facilitating division of labor and collaboration, and preventing conflicts when submitting data.
[0182] The event number selection box 1002 is used to distinguish the identifiers of different events. All event identifiers are kept unique to ensure that events do not generate duplicate numbers.
[0183] In the event execution mode dropdown 1003, there are two execution modes for events: loop mode and single execution mode. Loop execution mode is used to indicate that the agent will execute the event repeatedly unless it actively exits or is interrupted by external conditions (such as entering combat). Single execution mode is used to indicate that the agent supports exiting the streaming execution after the event is completed once, until it receives the command to enter the streaming execution again.
[0184] Add an event button 1004 to add a new event.
[0185] The main control panel 1005 is used to build workflows. A workflow must contain a root node as the starting point for the execution of events. Several steps (i.e., the above set of nodes) will be connected afterward. Each step is executed sequentially. Only after a step is completely completed will the next step be executed. The root node does not contain execution logic and is only used to identify the starting step of the workflow.
[0186] Step 1006 includes one or more execution nodes. All nodes in step 1006 have two execution modes: parallel execution mode and random execution mode. In parallel execution mode, all nodes in the current step will be executed in parallel. In random execution mode, one node will be randomly selected for execution during runtime.
[0187] Node 1007 is a child node of the original behavior tree that carries specific execution logic in the streaming execution. Node 1007 contains a root node and child nodes under the root node. Node 1007 has a unified base class pattern. Node 1007 includes at least one of the following functions: play emoticons, play animations, move, follow, and wait.
[0188] See Figure 11 , Figure 11 This is a schematic diagram of the data structure of the streaming execution event provided in the embodiments of this application, such as... Figure 11 As shown, an event is an array consisting of several steps. The contents of each step are explained in detail below.
[0189] Each step includes a step number 1101, an execution node type 1102, and a node execution mode 1103.
[0190] Step number 1101 is a unique identifier for a step, used to distinguish different steps.
[0191] Here, the data structure of the event provided in this application stores the execution nodes (i.e. the process nodes mentioned above) of all steps contained in a single event as an array. Under each array element, the step number 1101 to which the execution node belongs is recorded. The node associated with the step number 1101 is retrieved from the array according to the step number 1101. The node associated with the step number 1101 is a child node of the streaming execution node 904.
[0192] See Figure 12 , Figure 12 This is a schematic diagram of the node structure provided in the embodiments of this application, such as... Figure 12 As shown, the base class structure of a node includes multiple interfaces such as the start execution interface 1201, the continue execution interface 1202, and the end judgment interface 1203. The following is a detailed explanation of the multiple interfaces included in the base class structure of a node.
[0193] Start execution interface 1201 is used to execute the corresponding logic when a node enters for the first time.
[0194] Here, each node corresponds to a callback function (e.g., the virtual function "Execute()"). The callback function defines a start time variable, which is used to record the start time of the node. When the start time is empty, it means that the node is being executed for the first time.
[0195] Continue execution interface 1202 (e.g., virtual function "TickLogic()"), which is used to continue execution of a node when the node has finished executing for the first time but has not yet completed all the logic.
[0196] Here, when a node is executed for the first time, it is interrupted due to other operations. At this time, the node finishes its first execution. When the node is triggered again in response to an event, it continues to execute. That is, when the node finishes its first execution but has not completed all its logic, it continues to execute. Taking the node as an example for playing video, it plays each subsequent frame of the unplayed video. Specifically, when it is executed again, it uses the timestamp to determine whether the node has reached the playback duration. If it has not reached the playback duration, it starts playing from the position of the corresponding playback frame.
[0197] The "IsFinish()" checkpoint is used to determine whether a node has finished executing.
[0198] Here, we take the example of a node used to play video. When the video reaches its playback duration, we determine that the node has finished executing. After determining that the node has finished executing, we call the execution completion interface (e.g., the virtual function "OnFinish()" to end the execution of the node).
[0199] See also Figure 11 The execution node type 1102 is the specific logic of the execution node, such as agent movement, animation playback, etc. Different nodes have different configured parameters. For example, the parameter configured for the agent movement type node is the position of the agent movement, and the parameter configured for the animation playback type node is the position of the video frame, etc.
[0200] Node execution mode 1103 (i.e. the above execution mode) is used to determine the execution logic and behavior of a node. Node execution mode 1103 can be a random execution mode or a parallel execution mode. The random execution mode means that one node is randomly selected from all nodes associated with this step that belong to the random execution mode to be executed, which increases the unpredictability of the behavior and makes the behavior of the agent more diverse. The parallel execution mode means that all nodes associated with this step that belong to the parallel execution mode are executed at the same time, which is used in scenarios where multiple tasks need to be completed at the same time.
[0201] See Figure 13 , Figure 13 This is a flowchart of the execution event provided in the embodiments of this application. The flowchart of the execution event will be described in detail below.
[0202] In step 1301, the data corresponding to the event is searched.
[0203] Here, in response to an event being triggered, data corresponding to the event is retrieved. An event refers to a specific action or situation occurring in the system, such as a user clicking a button, the system receiving a signal, or a certain time point being reached. This embodiment of the application does not limit the data associated with the event; the data associated with the event can be the time, location, and triggering method of the event. After executing step 1301, step 1302 is executed.
[0204] In step 1302, it is determined whether data corresponding to the event has been found.
[0205] Here, if data corresponding to the event is found, step 1303 is executed; otherwise, execution ends and exits.
[0206] In step 1303, step variable i is set.
[0207] Here, the initial value of step variable i is set to a preset value (such as 0), and step 1304 is executed.
[0208] In step 1304, all nodes from the i-th step are collected.
[0209] Here, the step number of the i-th step is determined. Based on the step number, the node associated with step number 601 is retrieved from the array. The array stores the execution nodes of all steps contained in a single event, and each array element records the step number to which the node belongs. All execution nodes collected for this step are recorded as set S(init). For all nodes in S(init), they are divided into two sets according to different execution modes: a parallel set (i.e., the parallel execution set mentioned above) and a random set (i.e., the random execution set mentioned above), denoted as S(parallel) and S(rand). The parallel set contains nodes with the parallel execution mode, and the random set contains nodes with the random execution mode. All nodes in the parallel set and one node randomly selected from the random set are determined as the nodes in the final set of nodes to be executed (i.e., the candidate process nodes mentioned above). The node set is recorded as S(final) = S(parallel) + RandSelectOne(S(rand)) (i.e., the target process node mentioned above), where the RandSelectOne(*) function is used to randomly select a node from the random set.
[0210] In step 1305, the nodes are processed in a loop.
[0211] Here, steps 13051 to 13055 are executed for any node in S(final).
[0212] In step 13051, it is determined whether the node is being executed for the first time.
[0213] Here, if the node is being executed for the first time, step 13052 is executed; otherwise, step 13053 is executed.
[0214] In step 13052, the event corresponding to the execution node of the start execution interface is invoked.
[0215] Here, in response to the interruption operation of the event, step 13052 is terminated, and step 13055 is executed after step 13052 is terminated.
[0216] In step 13053, it is determined whether the execution of the node has ended.
[0217] Here, when the execution of a node has not finished, that is, when the node finishes its first execution but has not completed all the logic, step 13054 is executed; otherwise, step 13055 is executed.
[0218] In step 13054, the event corresponding to the execution node of the continue execution interface is called.
[0219] Here, in response to the event being triggered again, the execution of this node continues.
[0220] In step 13055, it is determined whether all nodes that need to be executed in this step have been completed.
[0221] Here, if all nodes of S(final) have been executed, proceed to step 1306; otherwise, proceed to step 13051.
[0222] In step 1306, it is determined whether the (i+1)th step of the event contains a node.
[0223] Here, if the (i+1)th step of the item contains a node, execute step 1307; otherwise, execute step 1308.
[0224] In step 1307, the step variable i is set to 1+1.
[0225] Here, after executing step 1307, step 1304 is executed, until all steps have been completed.
[0226] In step 1308, the execution mode of the event (i.e., the execution mode of the aforementioned target virtual event) is determined.
[0227] Here, when the event execution mode is loop mode, step 1309 is executed; when the event execution mode is single-event mode, the execution ends.
[0228] In step 1309, it is determined whether the number of iterations has reached the threshold (i.e., the loop termination condition mentioned above).
[0229] Here, when the number of iterations reaches a threshold (e.g., 3), the loop exits and execution ends. When the number of iterations is less than or equal to the threshold (e.g., 3), step 803 is executed again.
[0230] See also Figure 9 Condition node 905 is used to determine the direction of subsequent nodes based on the preset centralized data storage structure. When it is determined by condition node 905 that the data storage structure does not have an event number corresponding to the event or the current agent is in combat (i.e., the condition associated with the k+1th child node mentioned above), the behavior tree execution node 906 (i.e. the target tree node mentioned above) is executed. Among them, combiner node 902 is the parent node of condition node 905.
[0231] Execution node 906 in the behavior tree is a node in the behavior tree used to execute specific behaviors, containing specific logic or actions, such as "attack", "move", "pick up items", etc.
[0232] The following explanation, in conjunction with the aforementioned nodes, details the flow of the execution behavior tree provided in the embodiments of this application.
[0233] Since the execution priority of the left subtree of the behavior tree is higher than that of the right subtree, an encapsulation layer is added on top of the original behavior tree execution node 906, namely the combiner node 902. The left subtree of the combiner node 902 is connected to the streaming execution node 904, and the right subtree is connected to the original behavior tree execution node 906. The condition node 903 determines whether the condition for streaming execution is met. When the agent meets the condition for streaming execution, the node in the left subtree (i.e., the streaming execution node 904) will be executed first. Conversely, if the agent does not meet the condition (such as entering battle), the condition for executing the left subtree is not met, but the condition for executing the right subtree corresponding to the condition node 905 is met, and the agent reverts to executing the original behavior tree execution node 906.
[0234] The function of the combiner node 902 (such as a Selector node) in the behavior tree is to select the first sub-branch that meets the conditions from its own sub-branches, in a left-to-right order, and execute it. After execution, it returns to the combiner node 902 to prepare for the next selection. Mutually exclusive conditions are configured on the execution event flow and the combat sub-behavior tree. The behavior tree selects the appropriate branch to run based on the conditions. The condition decorator of each branch remains running throughout the game, performing a condition check on each frame of animation. If the condition of the currently running branch is not met, the combiner node 902 reselects a node in sequence and controls the agent to execute the event corresponding to the selected node.
[0235] The following explanation, with examples, illustrates the behavior tree switching process provided in the embodiments of this application.
[0236] Here, the behavior tree is a framework for switching between execution event streams and behavior subtrees. The streaming execution node 904 does not require configuration of specific execution steps for an event; it only accepts one input parameter (such as an event number). It queries a data table using the event number to obtain the specific execution steps corresponding to that event. The parameter is input from the event system to the behavior tree system.
[0237] See Figure 14 , Figure 14 This is a schematic diagram of the principle of setting event numbers provided in the embodiments of this application. The following uses event A as a phishing event as an example to explain the process of setting event numbers. The execution order of event A includes playing phishing animations, etc.
[0238] In step 1401, the data table is read to obtain the set of all behaviors that the pet can perform.
[0239] Here, as an example, the set of cat pet behaviors includes fishing.
[0240] In step 1402, the set of behaviors is traversed, and it is determined in a loop whether the behavior can be executed at present.
[0241] Here, the triggering conditions for event A are configured, such as whether the cat is near the shore. During the game, the event system checks the triggering conditions of the cat pet at a certain frequency.
[0242] In step 1403, if an action can be performed, the event number is passed to the behavior tree system and the loop is exited; otherwise, the next action is traversed.
[0243] Here, if the cat pet is not currently executing event A and the triggering conditions of event A are met (e.g., being on the shore), then the event number (e.g., event A) is passed to the cat pet's behavior tree system. When the behavior tree system receives the event number (e.g., event A) and the pet is not in battle (i.e., the condition associated with the kth child node), it starts executing the workflow corresponding to the event number (e.g., the cat fishing). If the cat pet enters battle while executing event A, then the behavior tree system does not meet the conditions for executing event A, and thus meets the execution conditions for executing the battle sub-behavior tree (i.e., the pet is in battle or has not received the event number, i.e., the condition associated with the kth child node), interrupting the execution of the workflow corresponding to the event number, and starting to execute the battle sub-behavior tree.
[0244] See Figure 15 , Figure 15 This is a schematic diagram of the first interface of the execution event provided in the embodiments of this application. Figure 15In the interface 1501 shown, the events represented by the streaming execution nodes in the execution behavior tree are executed, such as playing the happy expression of the pet 1502.
[0245] See Figure 16 , Figure 16 This is a schematic diagram of the second interface of the execution event provided in the embodiments of this application. Figure 16 In the interface 1601 shown, events represented by the streaming execution nodes in the execution behavior tree are executed, such as playing the animation of the pet 1602 teaching on the hillside and playing the animation of the pet 1603 learning on the flat ground.
[0246] See Figure 17 , Figure 17 This is a schematic diagram of the third interface of the execution event provided in the embodiments of this application. Figure 17 In the interface 1701 shown, when the character 1703 approaches the pet 1702, the pet 1702 enters battle, switches from the streaming execution node in the behavior tree to the behavior tree execution node, and executes the events represented by the behavior tree execution node in the behavior tree, such as executing battle logic.
[0247] In summary, the embodiments of this application use the same behavior tree to apply to different agents. As long as different event numbers are matched, different events can be executed in a streaming manner, avoiding the need to configure a corresponding behavior tree for a single event, thus improving the efficiency of configuring behavior trees and reducing the size of behavior trees.
[0248] The following description continues to illustrate the exemplary structure of the virtual object control device 555 provided in the embodiments of this application as a software module. In some embodiments, such as... Figure 2 As shown, the software modules stored in the virtual object control device 555 in the memory 550 may include:
[0249] The data acquisition module 5551 is used to acquire the behavior tree of virtual objects in the virtual scene, wherein the behavior tree includes tree nodes that represent virtual events that the virtual objects can perform.
[0250] The node selection module 5552 is used to determine the target tree node representing the target virtual event from the behavior tree in response to the virtual object triggering the target virtual event.
[0251] The event execution module 5553 is used to respond to a workflow in which a target virtual event is associated with a target tree node, and to invoke the workflow, wherein each process node in the workflow represents a sub-event of the target virtual event; according to the order of each process node in the workflow, the virtual objects are controlled to execute the sub-events represented by the process nodes in sequence.
[0252] In some embodiments, the event execution module 5553 is further configured to execute a start execution function; in response to reading a target event identifier for calling a workflow during execution of the start execution function, query a workflow configuration table based on the target event identifier, wherein the workflow configuration table includes correspondence between different event identifiers and different candidate workflows; determine the candidate workflow corresponding to the target event identifier obtained from the query as the workflow of the target virtual event, and call the workflow of the target virtual event, wherein the start execution function is configured for the target tree node.
[0253] In some embodiments, the event execution module 5553 is further configured to, in response to a callback function indicating that the target virtual event represented by the target tree node is executed for the first time, control the virtual object to execute the sub-events represented by the process nodes in the i-th node set in the virtual scene; in response to all sub-events represented by the process nodes in the i-th node set being executed by the virtual object, control the virtual object to execute the sub-events represented by the process nodes in the (i+1)-th node set in the virtual scene, 0<i<I, i is a sequentially increasing positive integer, and I is the number of multiple node sets, wherein the start execution function includes the callback function, the workflow includes multiple consecutive node sets, and each node set includes at least one process node.
[0254] In some embodiments, the event execution module 5553 is further configured to divide the process nodes in the i-th node set into a parallel execution set or a random execution set based on execution modes of the process nodes in the i-th node set, wherein the parallel execution set includes process nodes for parallel execution in the i-th node set, and the random execution set includes process nodes for random execution in the i-th node set; screen out candidate process nodes from the random execution set, and determine a target process node as at least one of the candidate process nodes and the process nodes in the parallel execution set; acquire a target node type of the target process node, and control the virtual object to execute the sub-event associated with the target node type in the virtual scene, wherein each process node is configured with an execution mode and a node type.
[0255] In some embodiments, the event execution module 5553 is further configured to, in response to a callback function indicating that the target virtual event represented by the target tree node has not been executed completely, execute a continue execution function configured for the target tree node; in response to reading the target process node corresponding to the interrupted sub-event during execution of the continue execution function, control the virtual object to continue executing the sub-event represented by the target process node in the virtual scene, wherein the start execution function includes the callback function.
[0256] In some embodiments, the event execution module 5553 is further configured to determine the historical pose of the virtual object when the sub-event represented by the target process node is interrupted; determine the current pose of the virtual object in the virtual scene when the target virtual event is triggered; control the virtual object to adjust from the current pose to the historical pose, and continue to execute the sub-event represented by the target process node.
[0257] In some embodiments, the node selection module 5552 is further configured to acquire a trigger condition for the virtual object to execute the target virtual event; in response to the trigger condition being satisfied, query a condition configuration table based on the trigger condition, wherein the condition configuration table includes an association relationship between different candidate conditions and different candidate tree nodes; when a candidate condition corresponding to the trigger condition is queried from the condition configuration table, determine the queried candidate tree node as the target tree node.
[0258] In some embodiments, the node selection module 5552 is further configured to, in response to the virtual object triggering the target virtual event, acquire a root node from the behavior tree, and acquire the trigger condition for the virtual object to execute the target virtual event; iteratively perform the following processing k times, wherein 0<k≤K, k is a sequentially increasing positive integer, and K is the number of child nodes of the root node: acquire the k-th child node of the root node; when the condition associated with the k-th child node matches the trigger condition, determine the k-th child node as the target tree node and stop the iteration; when the condition associated with the k-th child node does not match the trigger condition, acquire the (k+1)-th child node of the root node.
[0259] In some embodiments, the data acquisition module 5551 is further configured to acquire an initial behavior tree of a virtual object in a virtual scene, and construct a candidate tree node associated with a candidate workflow; determine a tree node to be deleted from the initial behavior tree based on a candidate virtual event represented by the candidate workflow, wherein the tree node to be deleted is configured to represent the candidate virtual event executable by the virtual object; perform update processing on the initial behavior tree based on the candidate tree node and the tree node to be deleted, and determine the updated initial behavior tree as the behavior tree.
[0260] In some embodiments, the data acquisition module 5551 is further configured to, in the initial behavior tree, determine the candidate tree node as a left child node of the parent node of the tree node to be deleted; determine the child node of the tree node to be deleted as a right child node of the parent node of the tree node to be deleted; delete the tree node to be deleted from the initial behavior tree.
[0261] In some embodiments, the event execution module 5553 is further configured to obtain the execution mode of the target virtual event; when the execution mode represents the cyclic execution of the target virtual event, the following steps are executed cyclically until the loop termination condition is met: determine the target tree node representing the target virtual event from the behavior tree; in response to the workflow associated with the target virtual event, call the workflow; and control the virtual object to execute the sub-events represented by the process node in the virtual scene in sequence according to the order of each process node in the workflow.
[0262] This application provides a computer program product, which includes computer-executable instructions stored in a computer-readable storage medium. The processor of an electronic device reads the computer-executable instructions from the computer-readable storage medium and executes the computer-executable instructions, causing the electronic device to perform the virtual object control method described in this application embodiment.
[0263] This application provides a computer-readable storage medium storing computer-executable instructions or a computer program. When the computer-executable instructions or the computer program are executed by a processor, the processor will execute the virtual object control method provided in this application. For example, ... Figure 3 The virtual object control method is shown.
[0264] In some embodiments, the computer-readable storage medium may be a memory such as RAM, ROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.
[0265] In some embodiments, computer-executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.
[0266] As an example, computer-executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files that store one or more modules, subroutines, or code sections).
[0267] As an example, computer-executable instructions can be deployed to execute on a single electronic device, or on multiple electronic devices located in one location, or on multiple electronic devices distributed across multiple locations and interconnected via a communication network.
[0268] In summary, in response to a virtual object triggering a target virtual event, a target tree node representing the target virtual event is determined from the behavior tree. In response to the workflow associated with the target tree node and the target virtual event, the workflow is invoked. Following the order of each process node in the workflow, the virtual object is sequentially controlled to execute the sub-events represented by the process nodes. Thus, by invoking the workflow through tree nodes in the behavior tree, the characteristics of the workflow simplify the configuration of tree nodes in the behavior tree, significantly reducing the traversal process for tree nodes in the behavior tree. This reduces complex calculations and resource consumption, improving the efficiency of controlling virtual objects to execute target virtual events. Furthermore, by invoking the workflow of the target virtual event, unified control of different virtual objects can be achieved. Specifically, different virtual objects can be controlled by invoking the same target virtual event's workflow when executing the same virtual event, without needing to configure a separate behavior tree for each virtual object. This improves the universality of behavior tree control over virtual objects, reduces redundant configuration workload, and enhances the maintainability and scalability of the behavior tree.
[0269] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.
Claims
1. A virtual object control method, characterized in that, Said method comprises: Acquiring a behavior tree of a virtual object in a virtual scene, wherein the behavior tree comprises tree nodes for characterizing virtual events that the virtual object is capable of executing; In response to the virtual object triggering a target virtual event, determining a target tree node characterizing the target virtual event from the behavior tree; In response to the target tree node being associated with a workflow of the target virtual event, invoking the workflow, wherein each process node in the workflow characterizes a sub-event of the target virtual event; Controlling, in sequence according to the order of each said process node in said workflow, said virtual object to execute the sub-events characterized by said process nodes.
2. The method according to claim 1, characterized in that, A start execution function is configured for said target tree node; Said invoking the workflow in response to the target tree node being associated with the workflow of the target virtual event comprises: Executing said start execution function; In response to reading a target event identifier for invoking a workflow during execution of said start execution function, querying a workflow configuration table based on said target event identifier, wherein said workflow configuration table comprises correspondences between different event identifiers and different candidate workflows; Determining the queried candidate workflow corresponding to said target event identifier as the workflow of said target virtual event, and invoking the workflow of said target virtual event.
3. The method according to claim 2, characterized in that, Said start execution function comprises a callback function, said workflow comprises a plurality of consecutive node sets, each said node set comprises at least one said process node; Said sequentially controlling, according to the order of each said process node in said workflow, said virtual object to execute the sub-events characterized by said process nodes in said virtual scene comprises: In response to said callback function indicating that the target virtual event characterized by said target tree node is executed for the first time, controlling said virtual object to execute the sub-events characterized by the process nodes in the i-th node set in said virtual scene; In response to all sub-events characterized by the process nodes in said i-th node set being executed by said virtual object, controlling said virtual object to execute the sub-events characterized by the process nodes in the (i+1)-th node set in said virtual scene, where 0 < i < I, i is a sequentially increasing positive integer, and I is the number of said plurality of node sets.
4. The method according to claim 3, characterized in that, An execution mode and a node type are set for said process node, and said controlling said virtual object to execute the sub-events characterized by the process nodes in the i-th node set in said virtual scene comprises: Dividing the process nodes in said i-th node set into a parallel execution set or a random execution set based on the execution modes of the process nodes in said i-th node set, wherein said parallel execution set comprises process nodes for parallel execution in said i-th node set, and said random execution set comprises process nodes for random execution in said i-th node set; Screening candidate process nodes from the randomly executed set, and determining the target process node as at least one of the following: the candidate process node and the process nodes in the parallel execution set; Acquiring a target node type of the target process node, and controlling the virtual object to execute a sub-event associated with the target node type in the virtual scene.
5. The method according to claim 2, characterized in that the start execution function comprises a callback function; the step of sequentially controlling, according to an order of each process node in the workflow, the virtual object to execute a sub-event represented by the process node in the virtual scene comprises: in response to the callback function indicating that the target virtual event represented by the target tree node has not been executed, executing a continue execution function configured for the target tree node; in response to reading the target process node corresponding to the interrupted sub-event during execution of the continue execution function; controlling the virtual object to continue executing the sub-event represented by the target process node in the virtual scene.
6. The method according to claim 5, characterized in that, the step of controlling the virtual object to continue executing the sub-event represented by the target process node in the virtual scene comprises: determining a historical pose of the virtual object when the sub-event represented by the target process node is interrupted; determining a current pose of the virtual object in the virtual scene when the target virtual event is triggered; controlling the virtual object to adjust from the current pose to the historical pose, and continue executing the sub-event represented by the target process node.
7. The method according to any one of claims 1 to 6, characterized in that, the step of, in response to the virtual object triggering a target virtual event, determining a target tree node representing the target virtual event from the behavior tree comprises: acquiring a trigger condition for the virtual object to execute the target virtual event; in response to the trigger condition being satisfied, querying a condition configuration table based on the trigger condition, wherein the condition configuration table comprises an association relationship between different candidate conditions and different candidate tree nodes; when the candidate condition corresponding to the trigger condition is queried from the condition configuration table, determining the queried candidate tree node as the target tree node.
8. The method according to any one of claims 1 to 6, characterized in that, the step of, in response to the virtual object triggering a target virtual event, determining a target tree node representing the target virtual event from the behavior tree comprises: in response to the virtual object triggering the target virtual event, acquiring a root node from the behavior tree, and acquiring a trigger condition for the virtual object to execute the target virtual event; performing the following processing iteratively k times, wherein 0<k≤K, k is a sequentially increasing positive integer, and K is the number of child nodes of the root node: acquiring the k-th child node of the root node; when a condition associated with the k-th child node matches the trigger condition, determining the k-th child node as the target tree node, and stopping the iteration; when a condition associated with the k-th child node does not match the trigger condition, acquiring the (k+1)-th child node of the root node.
9. The method according to any one of claims 1 to 6, characterized in that, the step of acquiring a behavior tree of a virtual object in a virtual scene comprises: acquiring an initial behavior tree of a virtual object in a virtual scene, and constructing a candidate tree node associated with a candidate workflow. Based on the candidate virtual events represented by the candidate workflow, tree nodes to be deleted are determined from the initial behavior tree, wherein the tree nodes to be deleted are used to represent the candidate virtual events that the virtual object can execute; Based on the candidate tree nodes and the tree nodes to be deleted, the initial behavior tree is updated, and the updated initial behavior tree is determined as the behavior tree.
10. The method according to claim 9, characterized in that, The step of updating the initial behavior tree based on the candidate tree nodes and the tree nodes to be deleted includes: In the initial behavior tree, the candidate tree node is determined as the left child node of the parent node of the tree node to be deleted; The child nodes of the tree node to be deleted are determined as the right child nodes of the parent node of the tree node to be deleted; In the initial behavior tree, delete the tree node to be deleted.
11. The method according to any one of claims 1-6, characterized in that, After controlling the virtual object to execute the sub-events represented by the process nodes sequentially according to the order of each process node in the workflow, the method further includes: Obtain the execution mode of the target virtual event; When the execution mode represents the cyclic execution of the target virtual event, the following steps are executed cyclically until the loop termination condition is met: The target tree node representing the target virtual event is determined from the behavior tree. In response to the workflow associated with the target virtual event, the workflow is invoked. According to the order of each process node in the workflow, the virtual object is sequentially controlled to execute the sub-event represented by the process node in the virtual scene.
12. A virtual object control device, characterized in that, The device includes: A data acquisition module is used to acquire the behavior tree of virtual objects in a virtual scene, wherein the behavior tree includes tree nodes for characterizing virtual events that the virtual objects can perform; A node selection module is used to determine a target tree node representing the target virtual event from the behavior tree in response to the virtual object triggering a target virtual event; An event execution module is used to respond to a workflow in which the target tree node is associated with the target virtual event, and to invoke the workflow, wherein each process node in the workflow represents a sub-event of the target virtual event; and to sequentially control the virtual object to execute the sub-events represented by the process nodes according to the order of each process node in the workflow.
13. An electronic device, characterized in that, The electronic device includes: Memory is used to store executable instructions for a computer; A processor, when executing computer-executable instructions or computer programs stored in the memory, implements the virtual object control method according to any one of claims 1 to 11.
14. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, the virtual object control method according to any one of claims 1 to 11 is implemented.
15. A computer program product comprising computer-executable instructions or a computer program, characterized in that, When the computer-executable instructions or computer program are executed by a processor, the virtual object control method according to any one of claims 1 to 11 is implemented.