Home Creators Posts Import Register Favorites Logout

Content

Hi! This is the second podcast about the inner workings of My Pretty Toy and today we're going to talk about the multi-purpose system that lets you do whatever you want!

More specifically, we will talk about how the thing that allows you to interact with objects, items, call various functions, effects, build furniture, etc. is structured.

Yes, almost all interactions and functions of game and non-game characters are built on only one system, which is very simple in its implementation, as well as in use, today we will talk about the Gameplay Task System.

Technical direction :

Usually, first of all, any developer prototypes the work of some mechanics, after which he builds a logical chain from them, which in turn becomes the basis for game and level design, in my case there were no problems only with prototyping...

The whole point of the problem was that it seems I tried to embrace the immensity and combine too many variables into one single formula, which eventually became a complete mess in the project code. I think it is very easy to explain to an ordinary player, or even just a person who is not strong in all these programming terms, that, for example, a game character should be able to perform functions and all the code of these functions should belong only to this very game character. This is an elegant solution in its own way, since we know exactly what this character does and what challenges he accepts in case of using these functions, but Mr. "open world" and Miss "interactivity" enter the arena, and here their rules come into force, which do not really like this approach...

You see, the thing is, we have a bunch of things that can interact with each other, and also this "bunch of things" must have a "bunch of functions" to do it correctly in each of the cases.

It seems that with the release of UE5, some kind of "solver" functionality appeared in the engine that serves such purposes, but I am not very willing to approach such solutions, since Unreal tools can be very cool, but also immensely overloaded. I obviously need something compact that will solve any problems without much fuss.

In general, the goal was this: in the game, almost all mechanics are somehow tied to the player character and NPC, they will have to perform some kind of "Actions", the execution of which may depend on the context, various factors, the results of checks, the type of character class, and most importantly - it is DESIRABLE to encapsulate all this work outside. What I mean.

You know, it's like sending an email. You give a conditional command "send", the server checks all the data between you and the recipient and does everything it should without involving both parties. It was this concept of interaction that helped to integrate a wide variety of functionality, as well as to conduct convenient debugging in case of errors.

Prototyping :

I think I introduced this system before the very first builds were released for general access, and it hasn't changed since then.

It all starts with the "Manager" component, which is contained by all characters inherited from the base class without exception. This component is a kind of fabricator, you tell it to perform an action - it either performs it or reports a problem, it's that simple!

In the screenshot above, we launch a task, or rather, we pass the task class, which the component accepts, for processing, after which it creates a virtual actor on the game stage, which will make decisions about performing its tasks based on input data and self-destruct after performing its functions.

Here, a collision problem is clearly brewing, since the solution of one task can negatively affect the solution of "another", already running task, or even cause the entire system to malfunction. The described task manager will not allow you to run several tasks in parallel, in order to certainly avoid such problems, because the character, as we can imagine, can only perform one task at a time.

But what if the task that we give the character must consist of several sequential tasks that have different functionality and require a different set of parameters. Obviously, we cannot afford to duplicate the code of one task in another, even by copy-paste, firstly, this brings chaos during debugging and secondly, it is simply not very convenient from the point of view of unification. The task tree comes into play!

Basically, a task tree is a central aggregator that can contain as many tasks as needed. It is important to understand that all the main logic is performed by the tasks themselves, while the task tree only ensures their sequential operation, and also has the ability to completely interrupt the entire sequence if one of the contained tasks requires it.

A task tree is exceptional for performing any kind of work, even if it contains only one task, since it provides a safe execution environment for the system itself, although it does not guarantee the correct operation of what is inside the task itself, lol...

After the task tree has designed everything it needs, it launches tasks from top to bottom. In the screenshot above, you can see how the task checks the conditions that allow it to do so before launching the main logic.

I think it's pretty obvious here that the same task can be used in different ways and by different performers (those who launch the entire process), and it would be nice if we could change the rules using the same tools we use to design the task tree, namely, add check scripts to the check list - and then let the task figure it all out itself. Which is what we do...

When creating a task, it creates objects ( Decorators ) that accept a certain "abstraction" as an argument, so that we can rely on something significant in the game scene. This argument is signed as "Contex", that is, in the context of who or what the check is happening, it could be anything at all, but for the safety of the check - all check decorators accept as an argument - the performer, that is, the character or actor of the scene who launched the entire sequence described above.

As you can see, the essence of the decorator is simple. It gets the necessary data from the provided context via interfaces (because it is convenient) and returns True or False during the check. In the screenshot above, the check is performed - whether there is a passenger in the carrying device.

This verification scheme has a number of advantages. For example, we can inherit tasks with a certain functionality and change the conditions of its application, say, for different groups of NPCs. As a result, we get a bunch of construction kit parts and build whatever we want from it, without the risk of breaking the structure itself.

Multipurpose Use :

In General, we have a kind of "conveyor" consisting of different machines that perform certain tasks and if at least one of the conditions of these tasks is against it - the conveyor stops its work and waits for new tasks. Now let's look at this conveyor in action.

Above is a diagram of the application of all objects that represent restraints, and by all, I mean absolutely all.

Since the task is an "empty" actor on the stage, it can receive data from the scene in which it is located and, as a result, influence other actors in the scene and do any tricks with them as long as this very task is being performed. In the example above, we receive data about the performer and his current goal, and also play various animation montages for everyone involved in the task, reset some parameters if the target is an AI-controlled character, etc., and then start the timer.

When you use objects or simply perform any functions - you can see the progress bar, this is the timer - the basic functionality of some tasks that are inherited from the TimeJob class. The thing is, some tasks obviously should be accompanied by animations, or objectively should not be performed in a nanosecond, such as tying hands. The use of the timer is due to these factors, and the timer also helps in some cases to cancel the current work if the user simply hurried and called it by accident.

Whatever the task using the timer is - it waits for the timer to finish, after which it calls the event inside which the magic should happen.

From the same example with the "Apply bondage" task, we simply call the function that the "Captive Component" contains, pass it all the necessary data that we received when constructing the task. As you can see in the screenshot above - the function has several outputs, this is the success of the operation and the reason for the failure (if the operation failed). In case of failure, we create a notification that will inform the player of the reason for the failure in the form of a pop-up widget, after which we give a signal that we have finished working on this task and can move on to the next one, if there is one (the exit from the task is indicated by a red and green outline). In case of success, we will continue the sequence and execute several more commands to remove the item from the inventory and remove the item from hands if it is no longer there and everything in this spirit.

By the way, we are not limited to practically anything when performing a task and can also compare any parameters during execution, such as the presence of an ability in one of the characters, redefine the logic on the fly or skip or interrupt the task, as well as stop the entire work of the task tree.

We have only analyzed examples of tasks that are focused on working on the "Performer - Target" principle, but the target can be anything, including the player character itself, and we actively use this. For example, we have a weapon that we can get and immediately start using, in this case we simply contact the manager who is responsible for weapons and simply pass him the weapon class, and he does his job. Although in this example we could do without a system of gameplay tasks, we still reserve for ourselves a simple way to call this functionality more compactly, without cluttering the base character class with unnecessary comparisons and checks, especially when we are dealing with complex systems and such isolation comes in handy.

Other areas of application :

The system itself is complex, which means that you can use its functionality in similar areas of application, say, in contextual actions.

When I talk about contextual actions, I mean a pop-up window with options for actions that you can apply to the target. This is essentially the same action window from RDR 2, only without the chaotic control via random buttons on the keyboard, lol.

Context actions are an add-on in the form of components (managers). Each character contains a manager, which in his case contains all possible options for actions that can be applied to the owner of this manager. If the character's legs or arms are tied - the manager performs checks (via decorators) and decides which actions from the list are currently available for the owner, after which it passes the list to the game character who is looking at it.

The whole point is that all possible actions applied to the target inside the context menu are the same, already designed task trees that are simply waiting to be launched. The only difference is that this menu contains only those tasks that must necessarily have a target with which one or all tasks in the tree will work.

As a result, we get another layer of interaction, which uses, say... actions that are quite necessary in most cases, or simply those actions that do something specific in a certain state of the character, for example, it would be stupid to add the action "Get up from your knees" to the radial menu along with a bunch of similar actions, while it can only be used in a very specific case.

If possible, I would like to completely remove the "Actions" tab from the radial menu in order to reduce the time spent searching for the desired action, but for now I am working on this solution.

Another add-on with identical functionality will be the assistant control panel, which will appear in the next update.

This is a slightly rethought contextual action panel with the only difference that the task tree, as well as the goal for completing the task tree itself, is transferred to your assistant. Thanks to the well-established operation of the gameplay task system, on which most of the game is based, we can create a variety of patterns from existing and used by the player tasks, the exception may be decorators (condition checks), but again we can inherit the same tasks, simply by making small changes to the list of checks, which eliminates laborious and tedious work.

Perhaps the only thing that differentiates assistant management from other systems based on gameplay tasks is the use of resources. When the player character performs actions - the actions rely on his capabilities and the availability of necessary components and items, and since managing items between the assistant and the player character to perform certain tasks could be a real pain in the ass - the assistant uses abstract resources that can be spent on completing the task (for example, sneaking up on a target and tying it up). You can think of this as a kind of game balance.

Conclusion :

I'm probably a little glad that I settled on this design scheme. The system of gameplay tasks is used in 90% of cases of communication and execution of any kind of work both as targeted actions, such as tying someone up, and as simple execution scripts (taking an object in hand, tying a knot, using an ability, etc.). Below I will list some pros and cons.

Advantages:

Clean design - a super simple way to tidy up the code by moving all unnecessary logic to task scripts and not cluttering up the base classes of characters, actors and other scene objects.

Ease of use - do you have a goal? You just say do it, without further ado! The entire task plan and the specifics of the work, the task itself is responsible.

Extensibility - Two extensions have already been built on the basis of gameplay tasks without changing the root system, which provide some space for easier use.

Ease of implementation - it does not matter what exactly in the game scene will use this tool - it can use it without any restrictions and edits.

Multifunctional solution - The system can act not only to perform tasks by actors in the game scene, but also as game services, such as the scheme for performing in-game missions, cutscenes and more...

Flaws :

High dependency - Yes, sometimes it happens. As mentioned earlier, 90% of communications in the game work on this system, which can greatly affect the operation of all systems using gameplay tasks when making changes to the root system structure.

Targeting issues - there are many inherited tasks that carry the logic of the predecessor, most of these tasks are goal-oriented, which, if careless, can cause unwanted problems in the form of control locks, unplanned launch of animation that cannot complete on its own, etc.

Volume of work - the gameplay task system is not a panacea and does not allow you to do something complex in a simple way. It only ensures a safe call and completion of the necessary functionality.

I think that's all for now, leave comments, join our discord server, and also leave suggestions in the comments for topics of interest to you for future podcasts of this kind. See you in the next episode!

Files

Comments

No comments found for this post.