MPT Kitchen - Operating Principles Of Bondage System. (Patreon)
Content
Hello! This is the first post in a new section about the kitchen design of the My Pretty Toy project, as well as a little about the problems and limitations, and a few more thoughts about the work done.
Today we will look at how the "General" bondage system works, what approaches were used in the early stages of development, what advantages it gives in the future of further development and, of course, its significant disadvantages.
Be careful, there is a longread below, for those who want to choose the most interesting for themselves - focus on the headings.
Basic Management :
The fundamental element of this system is the "Captive Component" component - this is a kind of manager of skeletal mesh components inherited from the "BoundMeshComponent" class, which in turn are simultaneously responsible for the visual component, behavior logic and are structure-forming elements. This component is used by every character in the game, be it an NPC or a game character, and every owner refers to this component in all cases when it is necessary to add, replace, remove an element of the chain, or remove all components altogether.
In general, the task of "CaptiveComponent" as any other manager is data management and optional storage of the cache of its activity. What it is really good at is managing implicit data based on generally accepted rules.
For example, we have a task - there is a certain object, which is a set of raw data (Analog of ScriptableObject in Unity), this object should presumably be used as an object, and in order to be able to use the same "entity" in different situations or with different purposes - action tags and destination tags come into play.
Gameplay tags are very convenient both in design and in use. In essence, these are "flags" that you can use to designate something and, based on them, build further logic.
In our case, they are divided into "Action Tags" and "Purpose Tags". In essence, they are the same thing, except for the context in which they are used.
Perhaps the only reason they are divided into two categories is that in most cases we only need one of these categories.
Destination tags are essentially the desired purpose in which we want to apply the item, while action tags are containers that can be transformed into several destination tags, after which, based on the rules, the most suitable one is used.
In the example above, we can get an "action tag" as input, which is described as "Arms". We check what destination tags it can be broken down into, after which we pass the data to the manager for further analysis.
In very simple terms, each equipped item has its own "destination tag" that is written to the CaptiveComponent. In essence, we fill the cells with something.
So we have three destination tags that could conceivably fit into the "Hands" or "LowerElbows" or "UpperElbows" slots, but what if the item isn't actually intended to be used in that context or something might get in the way. Let's say we have ropes that can fit into the "3 cells" responsible for the wrists, forearms, etc., but we also have an armbinder, what do we do in a situation where we want to keep the mechanism working as expected and not break the sequence with incompatible things? The insertion rules check comes into play.
Here everything is quite simple - it is a regular decorator ( possible / impossible ). The decorator knows everything about the object we are working with at the moment, as well as everything about everything that the component stores in itself, in case it is necessary not only to compare tags, but also to avoid the possibility of "collision" of incompatible objects.
In the example above, we check whether it is possible to insert an armbinder into the hand slot. To do this, it is enough to understand whether there is at least one item in the hand slot. Accordingly, if the check fails, we give the player a message that this should not be done...
There aren't many rules in the game, at least for now. This is also due to the fact that most items have similar uses, and say, a rule for using a rope with the "Hands" designation can also be used for shackles.
Once we've figured out whether or not an item can be inserted into a cell, perhaps the most controversial shit begins - choosing a style.
There are only 2 reasons why we should search for a style:
1. We only have abstract data about an object and some context of its use, and we clearly do not want to store a bunch of unnecessary data in an object that is used everywhere, so as not to cause staters when loading or creating these objects for further work with them.
2. We may have more than one object with identical purposes, which introduces problems with searching.
A stylesheet is basically a big directory for each item that stores information about what skeletal mesh to use for the item slotted into it.
In simple terms, we have a rope and a purpose - give me that damn piece of polygons so I can work with it!
In the end - having decided on the context of use, having checked the components and having searched for assets, we get what we want, with minimal risks of breaking something... Or rather, we get only a skeletal mesh, which is superimposed on the character, which we will talk about later.
Thoughts on CaptiveComponent :
Well, I'll probably start with the cons:
1. Not a very convenient solution to use, which requires too large a data base to verify parameters, which introduces quite a lot of confusion into seemingly ordinary work with data, especially in cases where "I left the computer for a while and forgot how this shit works..."
2. Damn A * n. The more items in the game - the more style checks, the longer the waiting time.
Pros:
1. Convenient integration of items based on similar ones - this is literally the best part, since some items only require a change in visual appearance and a slight change in their own parameters, which is leveled by copy-pasting data and replacing the target content in them.
2. Extensibility - we are not limited to conditional cells and we do not use the principle of "One cell - one functionality". Gameplay tags allow us to dynamically increase the diversity of assets, since we only operate with assignments, rules and styles, and do not bother about how the item will work at the instantiation stage.
3. Simplified implementation of third-party items (Mods) - if you tidy up the project structure, this can make it easier to replace assets with custom ones, since for correct operation you only need to specify a link to a new style, without affecting all the rest of the "vermicelli" from the scripts.
Many may think that the manager is too complicated and they will be right in general, but I conceived a flexible solution that will allow not only to do routine things, but also to experiment. In fact, you are not limited by anything, you can alternate objects, tie your hands with three different objects, etc.
Visualization of objects :
We ended up doing a ton of work and got "Skeleton Mesh"... Not much...
So here's the tricky part: Since we can't use a static mesh, for the simple reason that it will be a pain when we get to animation, we need another flexible solution that will save our ass.
The most obvious solution, and the one I still use, is a pre-made skeletal mesh attached to the original base character skeleton.
In essence, everything is simple, we transfer to the editor (in my case, Blender) our character in a "comfortable pose" to model our object, which will be worn by this character. If we proceed from derivatives - we need to make sure that the object will lie correctly on the body initially, cause minimal problems when combined with clothing, and also not cause visual artifacts when changing the pose or playing animation.
This leads to several significant problems with complex shapes. In the example above, it is obvious that we can apply the weights of one part of the rope to a specific bone so that they move synchronously and it is much easier to perform such manipulations with simple shapes, like ropes. I refuse some objects, purely because there are big difficulties with combining weights and combining objects with clothes, such as chest ropes need to be attached to the arms above the shoulder, above and below the chest, and also maintain balance when deforming at the bends of the torso. This simply leads to big problems with skinning and blowing up my ass, especially considering that the skeleton can have in addition to the main deformation bones - also correction bones, which contribute to the conditionally correct skinning of the character and breakage of everything else, lol ...
Overall this is a good approach, at least because we only need to model and hang the item once, eliminating the headache of animation effects, positioning, etc.
You're probably thinking - why do we need this at all? It's simple. We have a skeletal mesh, which represents the equipped item, and it is also glued to the base skeleton of the character, which allows us to dynamically embed it into the character and copy the current pose for natural behavior. Of course, you can simply attach all the components you need and switch them when necessary and get rid of the hassle of checking that I described above, but this is not a very flexible solution in itself, and it also carries additional performance costs and a complete mess if these components also execute their own logic.
A little about embedding. As you can see above, I use BoundMeshComponent as a base class for all objects that are intended for restraint. In essence, it is just a skeletal mesh component with a ready-made embedded asset that is attached on top of the character model and inherits its current pose. If necessary, it can execute the logic I need inside itself, again saving me from headaches in most questions, like "how do I do something when a gag is put on?".
This example demonstrates the work of a bag for the head. It creates an external system responsible for the blindfold effect, and also creates a kind of player for playing the breathing animation (deformation). All the components and systems it creates work for each copy separately, and are also deleted along with it, creating a safe execution environment, with no chance of missing anything.
It can also trigger events responsible for surface deformation, which was added recently after a global update.
In fact, previously these components performed only simple logic, but after the recent global update, much more dependencies appeared. Now BoundMeshComponent can also manage an external shape key manager, which is responsible for the deformation of the surfaces of all skeletal meshes that are attached to the character class.
It follows that a certain component can be embedded in a character and is able to apply a pre-prepared shape to some areas of the body or clothing to look more natural, as well as solve the problem with the composition of clothing.
Probably the only reason why BoundProject uses only tight-fitting clothing is the problem of combining shapes.
A little lifehack - I created for myself several blanks from the rope models that are used in the game, adjusting them to the T-Pose in which the clothes are modeled, so that I would know for sure where the elements will be located and where the clothes need to be deformed so that the two meshes do not overlap each other and look natural.
Along with the change in the approach to producing the visual part, Unreal physics assets were also added, which very conveniently fit into the existing components of the "BoundMeshComponent" class.
The essence is simple. We have a skeletal mesh of an object, this object copies the pose and generally behaves as we need, but what if we want to add some depth to the visualization, for example, dangling straps, remnants of fabric in the area of the knot, all sorts of ropes hanging from the bag, rings on the shackles, etc.? Everything is even simpler.
We just need to modify the original skeleton to which the mesh is attached, adding a few bones ( Depending on the complexity of the object ). UE5 does not allow you to copy a pose from a non-identical skeleton, but still allows you to do this if the skeleton has a similar structure ( Not necessarily identical ). Since we've only added a couple of new bones, we can easily import the modified skeleton as a new one and attach it to the base character skeleton, which will end up parsing the transformation of bones with identical names without affecting the bones we added.
Since the added bones remain untouched, we can create and apply a custom physics asset that will not conflict with other nested assets, giving us complete freedom in production and no headaches regarding collisions.
Of course, to avoid obvious performance issues, we build the asset's work through an animation graph, thereby being able to automatically turn off physics for characters that are at a sufficient distance so that its absence is not noticeable.
Thoughts on how the Bounds Mesh Component works:
On the downside - very, VERY demanding crap, in some aspects. However, this can be excluded from the downsides, knowing that in UE5 there are only 3 methods for creating a modular character and each of them is bad than good in its own way. This is all due to the fact that each component of the skeletal mesh copies the transformation from the original mesh (Character), which hurts the processor. To a greater extent, this is optimized in My Pretty Toy due to the dynamic transition to simplified inheritance for characters at medium and long range, but this still remains a big problem if there are too many characters, especially near the player.
On the plus side - this is, of course, simple and absolute control over each component individually, simple embedding, inheritance of logic from similar components.
Previously, BoundMeshComponents were simplified due to the lack of influence on external factors and the lack of physical assets and requirements for their operation. In general, this brought more problems than benefits, but there is still something to work on.
Animated State Machines :
Let's move smoothly to the elephant in the room. This time we'll talk about how animation works and how it relates to everything we've learned.
Let's start with the fact that animation graphs in UE themselves significantly simplify work with animation compared to their direct competitors, but like everything else - they have a number of drawbacks if used for their intended purpose without external intervention.
Above is an example of how the animation tree works, related only to the bondage system. It contains an entry point, which is also a key point for evaluating the pose, since we can get into a situation where the player puts on several items at once, or he simply loads a previously saved game - we must take into account what pose he took earlier, making an instant transition from the base animation to the target pose.
It is important to understand that animation nodes in a state machine can only compare conditions and cannot contribute to any functionality. This literally means that our animations and pose transitions should only depend on external data, or on the received data in its own state graph. I use both...
From the animation blueprint's own event graph I get enumerators that contain the currently relevant states, in the example above I get "Struggle State" which defines what kind of Struggle is currently in use ( Arms, Legs, Head, Body ) and also "Captive Anim Pose" - a sort of suggested pose at the moment.
We can then use this data to transition from one animation state to another. In the example on the left, we are evaluating the possibility of transitioning to the hog pose, on the left, the transition to the Struggle pose. Since Idle poses and Struggle poses work identically, we can rely on just 2 enumerators to evaluate the possibility of transitioning from one animation to another for any given state individually.
Since we only receive external data, and the data itself does not change magically - I use external state machines that can be accessed from any point in the code, change their states and perform transitions. They are something like an animation tree, or rather they provide similar functionality, except that they check for the possibility of transition from state A to state B - only at the moment of attempting this transition, and not constantly.
Perhaps what is good about external state machines is that we always know what states we can move to from the current one, and also check the possibility of this transition and consistently give commands, such as changing the camera position, setting the angle, playing sounds, switching the display of GUI elements, etc.
We have a controller that manages poses and there is a tree of animation states that decides how to switch animations. A reasonable question arises, how to properly mix wait poses depending on the presence of objects on the body, and also how to mix them with Struggle animations?
I had very controversial decisions about this before, but I settled on the usual mixing, as I call it - "According to circumstances".
The thing is that we have a pose "Sit on your butt" and it can change depending on the objects on the body, and along with them, the animations of the transition from pose A to pose B should change, including Struggle animations. There is no optimal solution for this problem, since we have 2 states between which we must move and only one transition point between them. In the long term, this imposes additional resource costs that will go to numerous checks every tick, moreover, it brings chaos to the animation graph, where it is already difficult to navigate. To solve this, I use a cache of state machines.
UE allows you to create state machines inside the animation graph, then cache the result and use this cache at any point in the animation tree. This is an optimal solution, since we only need to specify a reference to the cache in the transition from pose A to pose B, and we can do all the rest of the work in the state machine to which the reference to this very cache is attached. That is, in essence, we get a clear animation tree and separate state machines that decide which pose to use for the transition or for the Struggle animation, and which are also clearly lying somewhere to the side.
As you can see, the cache is used everywhere, both for the Move solution, the Target Pose solution, and the Struggle Pose solution.
Since checks for items on the body can have a significant impact on performance, especially when they are done every tick, we can hook into the "CaptiveComponent" event, which will automatically report slot changes and provide a list of equipped items as tags. Based on the tags, we can manipulate simple boolean states like "Hands tied", "Ankles tied", etc.
Based on the data obtained above - we can operate with conditions inside individual state machines, for example in this case we decide which "Struggle" animation to use "only" with bound wrists and thighs. As you can see we almost always need only one animation for one specific purpose, so the number of outputs can be huge, which would obviously introduce disorder into the architecture of the main animation tree, but not in our case.
Thoughts on how animations work :
Not the most optimal solution that can be used simultaneously on a large number of characters, but more obvious due to the lack of other options.
The most obvious problem with this approach is the additional work with animation assets. With the appearance of new objects, new poses, new Struggle animations, new transitions, etc. may be required.
A secondary problem is not the most convenient implementation of animations, although this is a problem of all animation graphs and its solution depends on your inner perfectionist.
One of the advantages is the obvious minimal load, since I can find an approach to solving the target animation by operating with primitives and do this only when necessary. Branching for certain situations allows you to adjust the necessary animations, as well as apply mixing based on the input pose or cache, in addition to this, debugging is simplified, thanks to which I can simulate problem areas and visually detect where the error was made in the animation graph.
Conclusion :
This is all pretty cool, except for the fact that this system organization is aimed more at a game where there are not so many playable characters or he is completely "alone" on the game map. I mean, there is a prevalence of overly demanding moments that adversely affect performance, but this is not a problem of this system, it is a problem of an ill-thought-out structure of the level design.
Initially, I focused only on the story campaign, where I could deftly operate equipped items, insert or remove characters as needed, and generally ensure the best work with these tools. The idea was not so much the ability to tie up all the girls on the map and bring them to one place (as most do who have sat in the sandbox mode long enough), but in advanced management of bondage items, complete freedom of action and determining solutions for current conditions taking into account the presence of these items in the inventory. Like many creators, I relied primarily on similar projects and the main thing I wanted to avoid was monotonous and one-button bondage, where you approach a character, press a button and the character will be tied based on a set pattern that cannot be changed. It's only fun for the first couple of minutes...
I wanted and still want to stay in the game direction, where the player can experiment, combine and use objects and actions to get the result that he least expected from this game, but which could surprise him, and the current tools can give this in the future.
On this note I think I'll finish, share your opinion in the comments, bring your own possible solutions, ask questions, and also join the ranks of spies on our discord server, there's a lot of cool stuff there!
See you in the next issue!