TRANSKRYPCJA 🔗
James: getting your code to work is easy, right? Getting to the c the compile is is hard for a lot of new people. But when they get there, they're like, Yeah, I'm done. Woo, let's go. Right. And we're on to the next one. but getting it to work without tanking your frame rate in the long run or taking five minutes to load a level, that's the hard part,
Spencer: This episode is all about code communication in the Unreal Engine. Indie Innovators is a podcast dedicated to independent video game development designed for aspiring and solo game developers. I'm Spencer Coral.
James: And I'm James Smith.
Spencer: And our show provides industry insights, expert interviews, and practical advice on navigating the challenges of creating a game from the ground up. Some key topics we've covered in past episodes are how to find the right game dev squad, toy box method, rapid game design, which all of the links for these can be found in our episode's description. And you can catch our episodes or become part of the community on a platforms such as Spotify, YouTube, Apple Podcasts, or even Discord. So if you're an aspiring game developer, Hello.
James: Hello.
Spencer: James, the Unreal Engine, that's what our focus is today Is this like code communication between like people on the same team, or is this code communication as in like the communication of code within the engine or
James: of the above. So yeah,
Spencer: Okay.
James: it it it it's it's literally getting your different scripts, right? Codes, objects, data, wa you know, whatever kind of structure you're doing, whatever kind of c class in your code to talk to each other and and to do it efficiently.
Spencer: th that doesn't seem like something important at all.
James: Well, getting your code to work is easy, right? Getting to the c the compile is is hard for a lot of new people. But when they get there, they're like, Yeah, I'm done. Woo, let's go. Right. And we're on to the next one. but getting it to work without tanking your frame rate in the long run or taking five minutes to load a level, that's the hard part, right? And and that's where learning how all of your code can communicate and when to use which method is Really important.
Spencer: So how often and this is I don't know if this is off topic or not, but how often when you know building something or implementing something into the engine, how often does the code, or at least the initial code that you've done have to be redone after? So I don't even know if I'm wording this properly, but it's like sometimes to figure out something that you want to put into the game, you've got to kind of just kinda just hammer at it from all these different directions until you find a way that it works and then go back after hopefully to you know re figure out it's like okay you know am I com you know I don't know communicating with these parts properly is is this gonna break some stuff in other areas you know is that kind of is is that code communication?
James: yeah.
Spencer: Or is that just debugging or or just v fixing things up nicely after?
James: well it's all the same, right? It's all the same process of how you're approaching your code in general. but specifically your communication is your your framework for how we have a player character interact with a door. Like how are we gonna decide that? How are how does a player know when they're up next to a door? How does a door know when the player is coming up to touch them? What happens when they pass through each other? Do they need to know anything? Does Does the door require a lock or sorry, a key for a lock? Does the player have a key? Right. How does the player interact with that door to get that information? Or, you know, vice versa. Like there's a lot of ways to look at that from the design perspective. But the code technical side is like how do we have okay, how do we actually turn that into proper communication and so it works? And then if you've seen a bunch of our or listened to a bunch of other stuff, you also know that how do we do that modularly so that every time We don't have to manually create that. and how common is it? It's very common. Like it's especially the longer a day a game goes in development. And I would I would argue that regardless of the size of the studio, the longer the game has been in development, the bigger and bigger the spaghetti code problem becomes. Just because you just have sheer volume of code that comes through and sometimes you don't touch some of it for months. And then later you decide, we need to change these elements. And if you haven't done things in an efficient way, in a modular way, you have to create hard references and you have to create additional functions just to support this one-off thing. And that leads to a lot of bloat and a lot of extra structure that just doesn't work in the modular fashion that I'm always like promoting. So Yeah, it's very common. It's very common. And especially with a lot of the novices and people who are getting it started in game development, you don't understand a lot of how this communication works. And a lot of the tutorial stuff is great. It's great to learn, but they're not teaching you when to do things or when not to do things. a prime example in Unreal that we see all the time is never use casts. Don't cast to objects. That's not true. There's a perfectly valid time to use them. But it is true if you use them too much, it will cause a lot of headaches in the long run.
Spencer: So what do you mean when you say cast to objects? Is that just like, you know, sending information or requesting something from an object?
James: Yeah, yeah. you're you're literally creating a reference, right? A digital reference to here is this class, this act or this file, right? Whatever, however you're setting it up in your code, but you're saying this is that thing. I'm going to reach out into the void of the game and say, I'm looking for you. And then you're gonna grab
Load full transcript
it and you're gonna say, Okay, I care about you. You're important for me to know. And that's a direct reference. Anytime I exist, this must always exist. So We'll we'll we'll touch on that, but yeah, we're we're basically
Spencer: So casting means like you're grabbing a direct reference from something.
James: Two You're getting a direct reference to something.
Spencer: that's right, 'cause it's okay, yeah, yeah, yeah. That makes sense. So then I don't know if this is the right maybe this fits better into later on in the episode, but if you why is that a bad thing? Because things need to get information. Or is it about how an object, you know, like puts information somewhere so that something can grab it from there instead of directly from the object, so that that way maybe things don't break if the object changes or I don't I'm j I fe I'm just trying to underst understand it better.
James: Yeah, okay. Well, direct references or casting, right? it's the easiest form for code to communicate because you're directly telling something Hey, coffee mug, I want to know how much water is in you or coffee or whatever, right? And then it gives me a response. But because I am saying, hey, coffee cup, at some point I'm gonna wanna talk to you. It always needs to exist now inside of our game world. That's a direct reference. We always need to know it's there. Because if at any moment this cup unloads, it breaks or something, now the code breaks. My code's not gonna work anymore. I'm not gonna know what kind of coffee cup I'm talking about. I'm not gonna be able to pull reference data for for how much is
Spencer: okay.
James: in there. And that goes vice versa. Maybe the coffee cup is direct reference to me as the player character, right? And it needs to give me a buff where, hey, for 10 minutes, boost my walking speed, right? Glug, glug, glug. Now I'm faster. Well, it's telling me, we shouldn't do that, but it's telling me. To make this change, right? So anytime this coffee cup exists, I must also exist. Because if I don't exist, then the coffee cups code isn't gonna work, right? So a lot of beginner code will break because they have invalid references. They have a lot of casting and a lot of stuff where we're specifically talking to something that doesn't exist in the world. And so the code doesn't know what to do. If you don't have a is valid check somewhere in your code, your code just goes, what? Whoopsies. Right. And then you can't figure that out. Which is why you always use that, especially when you're starting out. It's like, I need to know, is this valid? If it's not, then we don't care. Or maybe we want to do something else. We'd be hey, I don't it's not valid. My reference to my inventory slot item one is now empty. So when I go to cough or drink. Or I guess in a modular sense, use item, it's gonna say, I'm you're not holding an item that's not valid. And so instead of crashing or having nothing happen, we can say display, you know, tool tip on the
button screen, you're not holding something or hands empty, right? Like there's lots of ways of using that. But even
Spencer: Okay.
James: though I'm not holding that coffee cup, because my code is still referencing that item, that item must exist. So if it doesn't exist. In the playing space, it's going to exist in the memory inside the game, right? Because we have to load
Spencer: Yeah.
James: the data from that object. And that's a direct reference. So when do
Spencer: The coffee cup's a really good example.
James: yeah, and and so thank you. when do we want to use those, right? Because that sounds bad. And then in a lot of ways it is, but when do we want to use it? we want to use that direct call when the receiver is first of all known. Or cast only to check for a known reference, right? a specific type. we know specifically there is an enemy type in the world. So what we're doing is we're checking for an enemy. We're not checking for the scout enemy or the tank enemy or the fighter enemy, right? We're just looking for its parent class to be like, hey, is there an enemy out there? Great. We're gonna register it on the mini map. Do we care what it is? No, it's a red dot, right? That kind of situation is okay. so the reason that's okay is because your player character or your controller, right? What the player is is basically is in your game world is always there. You can't not play the game without that being loaded. Your UI also has to always be loaded. So if you did a direct reference to something and had that load up into your UI menu, it's okay. It's always there. If you have your UI looking at your direct reference of your player character or your controller and checking your health variable and updating a health bar in real time, that's perfectly okay. Your character or your controller is always present and your UI is always present. So there's no it's never going to load something into RAM in a wasteful way. It's always there. Where that would be bad is if my UI Is directly checking to see if the character I'm controlling in Unreal is of the type mage. So it can load a mana bar. That's bad because it's always gonna load the mage type of character, even if I'm playing a different class, like a rogue or a warrior, right? So it's always gonna check that and it's gonna load up that mage class. Depending how you've structured your code, that means anything that's applied to that what that mage character is also going to load because your UI is loading that character, even though it's not existing in the world. That's where it gets bad because the more stuff that that character is now referencing, let's say a chest that they find, you have the character cast to a chest to make sure you can interact with it and it gives you loot, right? When I'm loading when my UI is being loaded by my controller, and then the UI is then loading the mage class, which is then loading the reward class for the chest, it's going to load all that up into memory, even though none of that stuff exists. So it hogs your memory. And then now your game is slower. Now it doesn't have access to as much memory. Now it's doing garbage collection and processing on the behind the scenes that you don't know about. So that's why it's bad,
Spencer: Yeah.
James: right?
Spencer: Well it sounds bad because if you had a game where you were going around attacking enemies and if it had to referen like when you swung your sword at an enemy, if it had to reference every enemy when you go to like when the sword hits to figure out which one's gonna take damage, that would be like that'd be ridiculous. And so then so I don't like I'm I don't know if the terminology compar like matches between the two because I've been doing a lot of stuff with Godot instead of Unreal. and so I recently went through something like that where I had a character with that would interact with doors to open the doors. And when I was first testing stuff just to try and get things working I had it so that when the player interacted with the door, the door would then tell the player to like do this animation to open the door. Is that similar to like a cast kind of thing?
James: of it depends how do it. So what the cast is, right, and and why it's bad in the context of unreal, right, is that it doesn't find an object. It verifies them. Right. So I use the term is valid before. Well what it's doing is it's looking for an object and is saying is this true or false? Depending on how you've coded things, it must be true. And because we're looking for it. So it loads it. And then it does a comparison. And then it says, do I need you? No? Okay. It's fine. But the code is ran. The code has loaded that object. Even though you don't need it or it's not relative like relevant to the moment of gameplay, it's still loaded, anyways. So which is wasted resources, right?
Spencer: Mm-hmm.
James: and the more repeated casts you have like that, the tighter that coupling between code becomes, right? Between the caller and the receiver. So when you and a lot of novice teams will do this, they'll do direct references like that to be like, hey, when I press E, we're going to shoot out an array, right, from the camera, which is like a line trace basically in the world in 3D coordinate space to say, did I hit a door? If I did, we're gonna cast to see is that blueprint, prefab, whatever you want to call it, whatever game engine you're you're using, is it of type locked door? If it is, do this. Is it of type free door with there's no lock? Do this. Is it of type level load? Where if we open that door, it's gonna load a level and now we're inside a tavern, right? Like if we do a cast like that to see what type of door it is, that's a hard reference for every single door type. Right. So
Spencer: Mm-hmm.
James: very quickly it should be clear how many things become coupled and directly linked and then load all the time. Like you load into the game, and now we're automatically loading
into our RAM, our memory, all three door types I just mentioned on top of our UI, on top of everything else that we've casted to directly in our code. So the rule of thumb there, right, is is that Casting creates the hard reference, and the hard reference forces the reference actor to load into memory immediately, which can cause a chain reaction of loading. If you're ever playing a game and you see a hitch, right? You walk into a new area and everything stutters for a little bit, like that's a lot of loading. There's a lot of stuff that decides all of a sudden I need to I need to exist now. And everything needs to know about me right now. That's what can happen. so the bloat. With direct referencing, that's where you see it the most as on the gameplay side, right? As a pl as a player, or even just in testing, really. so yeah, if your main menu casts to a specific level blueprint, which then casts to a specific boss, because that's how you get past the level, right? If there's a constant chain like that where that boss now drops loot, which now drops this other thing, which now drops. an armor class lookup to see what kind of character you're playing so that it knows what kind of loot class to drop for your character type. Now you're loading the character and now you're loading all the inventory stuff. So very quickly you could see just by linking your main menu to your level blueprint and your level loop blueprint is like like it cascades. And so a lot of games, especially in the indie space, you see that a lot. A lot of game hitches, a lot of games where you press the start button And it takes a little while for the game to load up or start playing. And you're like, this is a little tutorial room with like a screen with buttons on it and a door for the next level. Why did this take so long to load? Because everything is loading. Right? That's that's the bloat that that happens.
Spencer: So this is probably why a lot of the stuff I've been hearing about is not to like have things direct reference and it's more of to just like have something like the like an interact where you know you interact with I have an interact action that if I use on the door, the door can tell, hey, somebody interacted with me. I'm locked, I'm just not going to open. Or you know, I need a key, I will check. the inventory to see if the person has a key. If not, you know, then so that then it's just kind of like like it's more of like a universal action that triggers the object to then do like its one time check of something and then and then move on.
James: Yeah, which is great. That's what we're gonna head into next. Is actually interface. That's awesome.
Spencer: Okay.
James: which is as a quick pause, right? For anybody who's listening. And you're in Unreal. Can't speak for Godot or Unity. But if you wanna fig see how this kind of works, what you can do is you can create a trigger box in your level and inside it, have it on overlap cast to your blueprint player character. And just apply damage or apply physics to something. That's a direct reference. But that's okay. It's okay because your player character always exists. It is always loaded in RAM. The only time it's not going to exist is going to be in a situation like a main menu where there's no pawn. It's just a purely UI. That's the only time the player character is not going to exist, but your volume is also not going to exist in that level either. So you don't have to worry about it. Right. So that's how you that's how you have to think about it. Is I it's okay to cast to something that is already loaded. If you want to mess with it, do it in reverse. Right. Have your player cast to your volume. And then do that for a couple objects and have each of those objects load to another object separately. And You'll see very quickly in your RAM or in your your size blueprint in Unreal how many things load just because you loaded into the game. Because your player will forcibly load everything it needs to know. So again, it's okay to link to something that already exists and has to, is already loaded in memory. If it doesn't always load into memory, you shouldn't cast to it. So casting to a game state, casting to a game mode, casting to a player character, player controller. casting to your game instance, any of that kind of stuff, perfectly fine. And it it will not damage your your performance, right? Ear frames per second or anything like that. So that's direct references.
Spencer: So if something's has like a just like a a a weapon again, like if the weapon has higher or lower modifiers based on the game like difficulty that a player's on, that's something that is that's fine to do like a a reference that to because it's something that's never really gonna change. The difficulty is just always there.
James: Yeah, right. Having a modifier of spine and in the context of the weapon, you know, on on hit or on shoot, right? We're still gonna cast the player character to tell it that I did damage to you. Here's my modifiers, right? We're gonna pass a function data along to them and say, I hit you, I wanted to make sure it was you. Yes, you are allowed to be hurt right now. I did five piercing damage, right? Then The player character will say, I received five piercing damage. What's my piercing armor rate? Now I'm going to do my modifications and take damage on that result. Right. That's how that you act.
Spencer: It still bothers me hearing that because that it's like okay to use in the situations because of all the modularity stuff that we've been talking about the over the last few episodes, where in my mind it's like, no, no, no, it's not okay. You need to do like a hitbox so that it when it the hitbox covers the the or the of the weapon overlaps the players, then it does like a little function that like puts damage on it. And then so that way you can like put that on anything anywhere. And it it just works.
James: Yeah. right. An example of making that
modular is in your weapon, you would cast to blueprint underscore hero master, right? Your master hero character that has all your hard code. And then what you do is you create a child blueprint for your wizard, rogue, and mage. So what happens is your weapon hits any one of those character classes, and because it's looking for a parent, that parent exists because the children that inherit. from it. It has to exist. So it still works. It'll still call the proper functions on all the different wizard, all the different like hero classes because you are talking directly to its like master, like its parent, right? That's okay. That still works. It's still modular. You could have any number of hero types and hero modifications and armor and whatever else is happening on your different heroes. And your weapons will still be able to damage the hero. Where that's bad is if you do it in reverse. I want the hero or the weapons to attack something that's not a hero. I want a player's sword to attack an enemy, right? The moment you cast that enemy through the player, the enemy has to exist, whether it's loaded or not.
Spencer: It also feels like something like this would be situational too, depending on the game, for what would be okay. Because if I have a companion following me as well and they can also take damage, then we can't have it just targeting like the or casting to the player, or like the the ma the hero or master hero thing, 'cause then what about my companion and how are they gonna how could they possibly take damage through it as well?
James: Well, why does your companion have to have a different structure, right? Intern we're speaking in terms of modularity here. They can still inherit from your hero master class. The only difference is it's not a player controller controlling that pawn or that character. It's an AI controller,
Spencer: Okay.
James: right? But all the code that that character cares about is still the same code running through your hero, which is why I called it hero master, not player master.
Spencer: that's right, that's right.
James: Right?
Spencer: Okay, that's cool.
James: So, so you can be very modular with this setup, but what's important is understanding that relationship that it verifies, it looks for the thing to exist. And if it doesn't exist, it will load it so that it knows how to verify. It's like it's like bringing up stat sheets, right? I don't know what to compare this to. I'm gonna load so I can look at the two and be like, I don't need this. But now it's still loaded in memory because you may at any point still ask me. To do that comparison. So I'm not gonna unload it. I'm just gonna keep it relevant because that's how game engines work, right? we need that data at runtime. So that's why it's important. Yeah, it it's it's
Spencer: This stuff is so cool.
James: really important to understand that flow of communication and when it's okay. So a as a rule of thumb, right? I I started to touch on this, I kinda glossed over it, I apologize. But as a rule of thumb, if it's not game system oriented, I try not to cast to it at ever. Right. I try not to use casts unless it's game instances, a subsystem that we've created for a project, if it's, you know, game states, player states, anything that's persistent inside your game, game modes, all of those things are perfectly fine to cast to. They're not gonna cost you any resources in your game. It's lightning fast, and argue you could even argue that it's a little faster to use a cast like that because it's already loaded. We just grab that information right away. We load it from the we just read our memory and be like, here's the game match, here's the store, here's the score, here's the game rules, it's all instantaneous. Perfectly fine, right? But casting to objects in your game world, it's not great. Right. Like and and and while it can work, like with the trigger example, right? That I'm asking people to try out, while that is valid, are you going to remember where it's working every time across all the different trigger volumes, jumping pads, loot chests, whatever else you've made, and to make sure that it's always flowing in the correct no,
Spencer: No.
James: no. Right. Which is why a lot of novice projects who focus heavily on this direct reference, right, casting, that's why they eventually run into spaghetti code where everything's just kind of like intertwined and you can't figure out what's happening where because there's just too much. It's too much to manage.
Spencer: That's
James: So how do we deal with that?
Spencer: yeah, how do we James? Cause I don't wanna have to although quick I'm assuming if someone's ever in a situation where they're unsure if it's okay to cast or not, it generally it's just like a don't. Unless you have to.
James: On honestly, is will what I'm casting to always exist? Is it always loaded? If the answer is yes, then yes, it's okay to use. If it's no, you shouldn't really do it. Right. You shouldn't you shouldn't do that. It's not gonna break your game if you do it once in a while. And there are gonna be used edge cases where you're like, Man, I don't wanna build a subsystem or I don't wanna build a persistent thing to support this like one interaction. You can get by by being a little hacky and just be like, it's a cast, it's fine, right? That's okay. Right. It the but the the problem is when then you forget about it and you keep doing that. And you keep making allowances and then now you have a hundred things loading and you're like, I can't understand why I can't get higher than twenty four frames per second. And that's only a sliver of what the problem could be. But when you have a thousand different things that are loading and on top of the rest of your game you've made at the end of tour development, right? You're nearing launch and you've got to get your numbers right. That's really hard to manage. It's really hard to figure out. It's really hard to track it all
down. it's super stressful.
Spencer: I got nothing to add, so
James: All right. As long as this is pretty clear. so yeah, so like how do we how do we kind of avoid that situation? Right? What do we do? So the next step up in complexity are event dispatchers or delegates. I believe Unity calls it broadcasting. I don't know what the equivalent in Godot is. But yeah, yeah. Basically it's a
Spencer: I don't know.
James: megaphone, right? If you if you want to think about it metaphorically. It's a metaphor, megaphone where you're just saying, Hey, I jumped in fire. And then whatever cares about me jumping in fire is gonna wake up and be like, I care. This is what this is the code that's supposed to fire, right?
Spencer: so okay, good be maybe something like a global variable or something like that.
James: Well, I'm assuming yeah. Right. But
Spencer: I don't know enough, I'm just taking a wild guess.
James: yeah. So so so to get a little more specific. it's a call and a response setup, right? Conceptually, it's the same thing as an observer, right? In like Minecraft, like I saw you, right? And publishers and subscribers. So the when that message is broadcast, right, like I took damage, right? The that's the publisher. Now the subscriber are the people who are looking specifically for that sound, right? Like that message where I took damage. And then they're gonna wake up and say, is this relevant to me? Depending how you've coded it. And then they're gonna process whatever they want to process.
Spencer: those the terms they use in Unreal Then, publishers and subscribers?
James: no, it's it's mostly d event dispatchers and then notifies, right? but
Spencer: Okay.
James: conceptually it's just easier to think about it as a publisher and subscriber.
Spencer: Mm, no, it makes sense.
James: Yeah.
Spencer: I was just curious because I it it didn't seem like sometimes all or yeah, it always feels like they try to use a more technical sounding term. But I I like the I like the what you use there.
James: yeah, so one sender announces an event, right, to any number of listeners. And this is where this is more powerful, is it doesn't matter how many people are listening or what is listening. And the sender does not depend on those listener types. So that hard reference that we would get from casting no longer matters because what happens is the player We'll say, I took damage, right? And so anything that cares about that, just off the top of the head, would maybe be a particle system, right? So it was like blood or particle effects play when the player takes damage. The UI would probably care about that message. So it knows, okay, you took damage. Well, I'm gonna go look at your health. And in that situation, that's where a direct reference is good. Because it's super fast. The UI and the player, like I mentioned, always exist. So it hears, you took damage. I'm gonna use my direct reference to check your health value and update that immediately for the UI, right?
But does it care how that damage happened, how much damage was there? No, it's only listening for that broadcast that I took damage.
Spencer: this sounds great because you say something once and then a whole bunch of things can just start reacting off of it versus a bunch of stuff happening to go, Hey, do you have that thing I need? before they can
James: Yeah.
Spencer: start doing their work.
James: Yeah. So just to stick with the dungeon thing, because I went that way, right? RPG style. if you think about it like a l linear level, right? Just there's tr hidden traps. If you step on a stone switch, what you could do is you can create a broadcast, right? A event dispatcher, which is in Unreal, which is going to say, I've been stepped on. Now you can include a bunch of information with that as well. Or you could say, This is me, a self-reference. So you could do a tie there if you wanted to. you could do a type reference. You could say this is what stepped on me. Maybe I don't care if an enemy type stepped on me. Maybe I don't maybe I only care if it's a player type. That's like a soft reference, right? So you could pass that along. You could pass along different attributes like damage, timer. Counts, delay counts, cooldown, whatever you need to pass on information. You can you can apply it to your broadcast. And if nobody cares about that information, it doesn't do anything. It's just a message, right? Like a bulletin board. Now your traps on the other end of the wall, or your floor pit, your spike pit, whatever you want to call it, your gelatinous cube trap, right? All of that stuff is listening for that message where it's like, you button one was stepped on. Okay, who cares about button one? Well, it's the two doors that are gonna swing down and play an animation, and then also the slime who's gonna activate and turn on physics so he like plops down into the level, and then we turn on his AI so he like starts you know, sliding towards the player character. All of that we don't need a direct reference. Nobody cares what exists in the world, nobody cares if the bright button is pressed or not. All we're listening for are for a specific cue. Which is trap one. I guess that would be a better delegate name to be fair. Say trip trap one was pressed. Who cares about trapped one? And what's nice about that is that you can swap that in and out. You say, actually, you what? I don't want the Gillettinous cube to be first. I want the arrow trap to fire first. So inside the delegates, I'm gonna tell the cube to bind, which is to listen, to subscribe to that event, right? And I'm gonna change it from button one to button two. I'm gonna I'm gonna go find that reference and say, I'm gonna listen to you. And then I'm gonna change it for the arrow trap and say, hey, instead of button two, you're now gonna listen to button one. And so you can change those those edits.
Spencer: This sounds way better than casting in a situation like this, otherwise 'cause if this
was casting, like either the trap would be constantly checking the button if it's been stepped on, or the button would constantly be sending back like, Hey, I haven't been stepped on, I haven't been stepped on. And that's just like a whole bunch of stuff that would be just processing that doesn't need to be.
James: Yeah, right. So if you ever think about a a dungeon trap where you have to hit certain order of buttons or stones on the ground to unlock a door, right? Or maybe switches. Maybe you have to hit the switches in the right order. What you can do is you can have the switch say, My name is switch one. I am on or off like a bool, and it just announces that. So whenever the player hits switch one, it just announces its state. Where it says, I've been touched, and here's my flag, right? I've been moved. Here's my flag. And then so you can compare on your door who listens for like when the switch has been touched. Now, so what I'm getting at here is you don't code that event delegate, right? For every single one, the event dispatch. You don't make one for every single switch. What you do is you create one switch, one blueprint. You tell it to have this event dispatcher with a little flag on it that says true or false and then whatever you want to call it, right? Tooltip. Please use tooltips. And so then your door, what you can say is, Hey, I'm going to tell you to listen through a direct reference. So they're kind of tied. You're gonna say, I'm gonna get the switch who exists in the game. But I don't want to do anything with it. I just want to find its code. For when it's talking about when it's been switched. And I'm gonna listen to that. I'm gonna bind an event or a function to that when that happens. So when you flick a switch, it's gonna, the door's gonna know, I'm supposed to be listening for this. Now, what you could do is you can code the door to say, I want you to have three switches. All three of them must be true before you open, right? Your one switch, you can duplicate it, move it all around the levels, make them in different orders. You could do it as sequentially if that's how you wanted to do your puzzle, right? But I'm just thinking you have to go into different areas to hit all the switches, and then it opens up the dungeon door, right? When I hit that one switch, well, it'll activate. And then in its flag, we just say this is door one. And if you made that a public or an editable variable in Unreal in the details panel. You could tell it that you could click on that switch and say you are door one. Go to the other switch. You are you're sorry, lock one. The second switch is lock two, second third switch is lock three. And then you go interact with each one of these switches and it's gonna activate, tell the door a switch has been turned or just you know, switch to a different position, and then it's gonna read what that flag is. Is it true or false? You know, open or locked, unlocked, however you want to do it. And then you can have another function inside your door separately where it doesn't cast to those switches. What it does is it just keeps an internal log of which switches have been turned on. So when we hear that event, switch one is on or unlocked, it's gonna load up on its own and say, okay, switch one was unlocked. I'm gonna remember that through a local variable. This is switch one is okay. And then when switch two is done, we're gonna listen and say, that was switch two. We're gonna we're gonna unlock that one. Right. Somebody goes back and hits switch one again, we're gonna lock it. We're gonna reverse that. And so we're we're not actually caring what's happening to the switches, we're just listening for what happened and making our own decisions. So eventually when all three are unlocked, then the door says, Okay, all three are unlocked. We're now gonna call this function or we're gonna trigger this event, which is I don't know, the bars move out of the way and the door opens. Right now, what's really nice.
Spencer: That's awesome. Cause like if you were wanting to do like a sequential one then, you could have it where it it's like it knows what it's supposed to be listening to first and second and third. And if it gets something out of order, then it sends out something that the like a reset thing that the switches are listening for. And so if they get the reset, they know to just toggle themselves off or something like that.
James: Yeah. And that's how you would do that without that direct reference. What's really nice about that, it being modular, is that you can have any number of switches you want in that scenario. Your door could have one switch, it could have no switches, it could have five switches. Once you understand a little bit about like procedural generation, you could randomize it. You could say, Okay, first things first, door must exist. We're gonna randomize how many locks it has. Then we're gonna randomly pick spawners across our world. To drop these switches in. When when you go to hit play, all those switches and doors and that door, excuse me, are automatically connected. The code works. You've already programmed it once, it doesn't care anymore. That's a little more complicated to set up, but that's like it doesn't require any more work after setting your initial publishing, right? Your event dispatcher, and then your bind, which is your subscribing, right? Once that publishing and subscribing relationship is set up. You don't have to worry about it, yeah. You can move it anywhere in the world, in your game game world, and it'll work. And then yeah. Anything you want to work outside of that, you do it inside of the actor that's listening.
Spencer: That's awesome.
James: Yeah. So there is an element of direct casting that is still relevant there because the door needs to say, I need to know what a switch is, right? I have to load that switch so that I understand what that broadcast message is. And this is a part that I find a lot
of people skip over. So the direct casting is still there. The difference is the door is the one object who is listening, who is subscribing to whatever is speaking. We don't want that door to s to load every single instance of those switches. We just want it to load the code for the switches once so that it understands what that broadcasted message is, what the publishing message message is. And then we want to tell the door to bind, right? To subscribe to that event. So anytime that is shouted into the game world, the door knows how to react.
Spencer: I'm assuming in a situation like this, if one door like once one door loading the switch means that all the other doors don't like it, they're all like the switch is loaded once and all of the doors just kind of know how the switches work that use switches.
James: Yeah, that's that's the advantage of how that works is you do the one cast, the one time the door now understands. It knows exactly what to do. You could have infinite number of switches in there, and anybody who's listening for those switch broadcasts
Spencer: And it doesn't it doesn't make it any more taxing.
James: No, it's cheaper because we're not gonna cast every time. We're not gonna try and load it every time. It's loaded once and then we forget about it. It's just stored. So so there is a memory footprint to doing dispatchers and delegates, but it's way more modular and it's way more forgiving. Right. And and you can have anything listened, right? That's that's that's the other part of this where it's nice. You can have anything listened to anything else. It it's still good, right? G in in practice to not cast two things that are not necessarily going to exist in the same world. Like you don't want a boss to know about the switches. Cause anytime the boss loads, he's gonna load up the switches. And depending how your game is designed, right? How you've made your world, if you are doing like a boss arena that you load into as a separate level, that boss should not know about the switches. Otherwise it it will load them. Right? Because it's a direct reference. It has to. So you don't want the boss to listen to the switches. However, if you're doing a setup where it's all in the same level, there's no separate loading, and there is a specific switch that does spawn the boss. Maybe it's a hidden boss. And like I said, it's all in the same game world. It's perfectly okay for that boss to have a direct reference to switches, specifically listening. and subscribing to that one switch which triggers the hidden boss. That is okay. 'Cause the switches are already in the level.
Spencer: I love the idea of a boss just having a tr a secret little like thing where he's always loading the switches cause you've just decided that the boss loves switches, but
James: Yeah, and like there's a lot of there's a lot of nuance there. Like it would have to be like a real time spawn in and like he just like drops in from the ceiling or something. Like it
wouldn't be like a cinematic reveal.
Spencer: no no it's like a secret behind the things. he just loads switches cause you've decided that the boss loves switches. Nobody will never know. And they're not in that level, but it's just like some secret lore.
James: Yeah. Or, stuff like weeping angels. Yeah, weeping angels are a great example of that, right? It's just that it's just a big statue in the corner, but you happen to hit the switch and now it's like, okay, now I'm alive, right? Right. And that's one example of how that could work. This is this is like bugging me. I gotta like get that little curl in there. There we go. well I I just can't not see it. Anyways, yeah, so that's like when you want to use it, right? So a boss dies. and it's really you effective across multiple blueprints, right? So if the boss dies, we want the UI to update, we want the achievements to pop up, we want music to change, we want doors to unlock, we want loot to drop, like those are all different systems. We don't want them to have direct references to each other, because that's a lot to load. But if they're just there, they exist and they're just listening for the boss and the boss died. Well, all the things that care about that boss dying in your design, you could set up to subscribe to that event and they all run and it doesn't cost anything. And there's no direct reference area, it just it just they listen for that event. So where was got off topic with my notes here. gate listener, nope, talked about the gate. yeah, so if you want to try that, right, as a listener and you're in on real, you can create a button blueprint with an on button pressed event dispatcher, and it's it'll be in the bottom left over right in your variables on the very bottom. and you can create a separate light blueprint just in the level and just have a bind event. Where on begin play, the light is going to look for that event from your button. And it's gonna play a sound and I don't know, you could change the intensity, right? For your light. And so that becomes a button where you press the button and the light just will flicker on and off by itself. Right. You don't have to tell the light to turn on. It knows to do that because you push the button. And so could do a lot of neat stuff with that. You push the button, the doors open, the lights all turn on in sequence. you could get really complicated with some of that stuff, all just from a button press, right? That's how the event dispatchers can work. But that's that's how you can try that. Now, another like, are we should check in? Does that is that pretty clear? Like how the yeah, awesome, cool.
Spencer: No, that's awesome.
James: the next one. is on par in terms of complexity and this is the interfaces that you were talking about. And it's this is much more decoupled. It doesn't need to have a cast to set up a broadcast and you know a subscriber publisher relationship. Like that doesn't matter anymore. So what it is, is it'll it's a
way to communicate different types of when different things need to share a single request. Right. what it is effectively happening is you're asking the thing that you're interacting with, do you have this function that I that you've written without needing to know what the object is? So we don't need to cast it all. We don't care. We're just saying, do you take damage? And we're leaving it up to whatever we're hitting to decide yes or no. So our code is always running. We're be do you do damage? Do you do the damage? Do you do damage? No, no, yes, okay. I don't care. I just told you to do damage. And now that actor is gonna do whatever it needs to do when it takes damage. Right? So When to use that is for interaction systems, damage is a good one. and triggering generic events, right? So use item is a great one, right? So you create a interface or interface library, depending on your game engine. And in that you have on interact is a very common way of naming your functions with these. And so how that would work is In gameplay, if we are in the game world and we left click, and maybe it it doesn't matter if it's swinging an object and on collision, or we are casting from the camera to hit an object in the world, whenever we have that collision with an object, we're just going to tell it, hey, do you have this interface? And we do that by just telling it to do something through the interface. We say, we want you to do on interact. Now, if we hit a tree that doesn't have on interact, it's not gonna care. The code will still run, it's still gonna where our player, our character, is still gonna tell it, hey, I interacted with you. And the tree's gonna sit there and say, That's nice. Right? Nothing's gonna happen. That's cool.
Spencer: Yeah, that's cool.
James: But if you come up and you hit a bell and the bell has the same interface, what you can do is you can code on interact to have its own bespoke. Code that the bell is supposed to run. So when the player character comes out, hits it with an object and says on interact, the bell's gonna go, I'm supposed to ring and play this wobbly animation. So it'll do that because it does have that interface. Now we don't care that we hit a bell. The memory does not need to be there. We're just gonna tell it, like subs, like a publishing and subscribing, right? We're gonna tell it this happened. But the only thing that cares about that message is that thing we directly interacted with. So that that's how they're different from a dispatch. A dispatch and a delegate, right? Anything that cares can listen to that event and run what it's supposed to, which is why it's good for things like the boss dying and you want achievements and UI and like all these things to trigger. Right. That's good. But your interface is more for one-on-one relationships. Is that is there any questions there? Is that is that is that good?
Spencer: Yeah. No, sorry it's there's a lot of the stuff where I'm just thinking like, man, this is
great. This is kind of this is I'm thinking about the process in my own Godot project where I'm like, yeah, okay. It's not the exact same terminology for it, but I'm like trying to just I'm just as soon as we're done the podcast, I'm going right into to work on my game now. So
James: Yeah. So so in your context, right? If you created an on interact interface, right? And
Spencer: Mm-hmm.
James: so the way you would do this is you would create an interface library that is items, just for argument's sake. And inside that you give it a bunch of functions. On interact, on break, on pickup, super generic, just things that all items need to do. Anything I can interact with, what are all the possible ways I want to interact with it? And you create those as functions. And so this way, whenever you're in your game world and you're up against a console, you have a character you want to connect with, you're coming up to a door, you're at a window, you're at a different object in your game world, you're at a storage chest, you name it. You just go up to it and say on interact, this is what's gonna happen. And so once you've coded that, your player can press E and it sends that message to whatever the player is interacting with, whether that's through casts, overlaps, etc. They all work the one time. It's permanently like that. Anything that has that item will run that code. Now, if you think modularly and you build a master blueprint for interactables, which is a very common way of doing this, right? You give that master blueprint that interface as a component. Every child type that inherits from that parent class will just automatically be interactable with, regardless of what that is. Right, it could be men, like I said, menus storage chests, enemies, ragdolls, you name there's there's tons of potential there for whatever you need. As long as it's generic, you never be specific.
Spencer: Mm-hmm.
James: You be specific in the like the listener, the receiver, right? So your door has a very specific code it's supposed to run, which is open this way, check for key, do etc. Your window has its own separate code, your inventory systems pull up a different set of code. And so that's where you can make it specific. So your modular your modularity, right? Your design for that is all in how the things communicate with each other, but specifically what they do is where you can still be you know bespoke. You can make custom custom work.
Spencer: Well, 'cause that stuff's great because then you can like interact. I like once I have the stuff in my characters so that he does like an interact and then broadcast that to whatever is in front of him or whatever. Like anything that I create and put into the game that I want the player to be able to affect or change or do something by interacting with it, the the code's already there. Like the it's just a w you know. The player uses it and it doesn't matter what I create or put in later on. It's like the interact function is there and it's it's I'm just playing around
James: Yeah.
Spencer: with that stuff right now and it's it it it means that like I can just make one I I basically make one script for doors and then I just apply that to like 12 different styles of doors if I want to and then it just they all just work. It's just like Coding and building at the one time i i is really all it took, except for like maybe some minor modifications for some of the other ones. But James. James, it's beautiful.
James: Yeah, and and the same thing works with NPCs, right? You still interact with them. You can give them the same things so that the player can still walk up, press E, and then you just code what's supposed to happen in there. Right? So so
Spencer: Yeah. Well, it's like all the NPCs too can be like the same base thing where it's like here's here's the package of everything every NPC will need, and then all of the other NPCs will just grab the all the NPCs grab that and it's like this one's like a I don't know, like a guard. So now he's also got like some like d weapons and damage stuff. And then like here's my merchant, but still has all the same base NPC stuff, but now he's got like a a window that you pops up so that you can buy and sell stuff with them and it's just So cool. When we were
James: Yeah. Yeah, yeah. Exactly, right?
Spencer: going to school earlier, if I wish we had just the kind of references that are out there now. And you know, maybe we had them back there and I just didn't know how to look for them. So maybe that's the difference now. But this game making games would have been so much fun back then.
James: Yeah. well I I think that a lot of the educational institutes struggle because they have like requirements for their curriculum and all that kind of stuff. But it's also really hard to explain this stuff to a bunch of students and be like, no, like there's no possible way to grade you guys in like a nine week window if you have access to all these modular tools and stuff, 'cause how do you grade that in like a weekend? For a class of 20 people, that's really, really difficult. To be fair, to be fair, as much as I dump on and like things like that. But no, no. Yeah. But there are a lot
Spencer: Yeah. Well I I didn't mean any shade on them, I just meant there's just so many awesome sources online.
James: of people who ask that, right? E even now when I'm at different events or conferences and whatnot, peop people sometimes ask that and they'll be like, Well, we heard some stuff, read some stuff, and what are your thoughts on this? And like that's the that's the drawback of having a certified program that you could go learn from. It's very regimented. So you're probably not going to learn this stuff. You're probably going to learn direct referencing. You're probably going to learn how to do a very basic code for a game, which is going to be like game jam level. Like you start the game, you have a problem, earn a score, whatever, you end the game.
There you go. You made a game. You're a game developer. Nothing wrong with that. That's true. Right. If you could do that, then yeah, you're a game developer. Right. But do you understand the nuance of like a studio grade job? Probably not. Right, because all these things have there's a lot of information here. And there's already your gears are spinning. And I hope anybody else who's listening, their gears are spinning. And every everybody listening or thinking about it all has their own ideas of how this could be implemented and how this could change things and how this could like make everything modular, but also greatly expand the scope on things. And like, yeah, so it's hard. It's hard to explain this stuff in a way where you can answer questions and you can go through stuff. That being said, if you're listening and you have questions.
Spencer: i it's in some ways it sucks for doing this podcast episode right now because halfway through the stuff we were talking about, I'm like, I just want to go and start using some of this.
James: Yeah, but if you've listened or you're running into this, join our Discord, just ask a question. I'm usually always around working too much. So when I have time, I'll answer it and yes, feel free to stop by is my point. Self promotion sheen. yeah,
Spencer: Yeah.
James: so that but anyways, for for like how to try that, as somebody who's never made these before, create a BPI. Right is blueprint interface in in Unreal and just call it interact interface. It's the easiest one to do. Give it the on interact function. And then you can apply it to doors and you can apply it to switches. You could do it through a line trace to make it super simple. So wherever you're looking, it just sends out a cast to be like, I interacted with you and play around with it. You'll see very quickly how easy it is to create multiple things that stem from that one interaction. Right. with a player pressing E. What can I do with that? Well, I can break things, I can move things, I can pick up things, I can activate physics on different objects, like and play animations. And so that greatly expands your toolkit, basic as a developer. And like I said, it's it's it's not free resource wise, but we don't have any casting, we don't have any direct references or soft references. It's purely just I told you to do something. If you're not gonna do it, that's fine. It's harder to debug sometimes because you think you've set it up correctly. And if you haven't, or maybe something in the code specific to that item is broken, it's a little harder to chain those those interactions. So
Spencer: yeah, cause son it'll just not do anything versus like errors popping
James: Yeah.
Spencer: up.
James: Exactly. So so you do have to be a little careful, right? And that's also why I I'm like insisting on generic. It's gotta be very simple. You don't want to have your interfaces do complex code, right? They're not meant for that. They're just meant for I triggered this event. Now you do the thing you're supposed to do when this event happens. And that's it. Like you can pass along.
Spencer: So it's like a interact reaction thing versus interact and then go build me a pizza.
James: Yeah, or or specifically build me a pizza, right? You don't want that as a as a interface because Hawaiian pepperoni half folded upside down. what does that mean?
Spencer: Yeah. Now it's spawning all these things in into its memory and
James: Yeah, you you don't want that, but you do want on interacted, and then it's pops up a menu or a timer and it says pizza cooking and then UI adjusts, and then all that is contained on that pizza oven model. All you cared about is did it have the code for me to press E on it? And it worked. Like you wanna see you wanna see games that are like built around that kind of interaction? Any kind of shop simulator style game. That's in essence how interfaces work. Where it's just I pressed E, I picked up this thing, I'm holding it, I pressed E again, it this item moves to that item, right? It's it's very simple. and it's meant to be that way.
Spencer: And not to throw shade and this isn't me throwing shade on the shop simulator games, but I understand now why there's so many of them. Because it's it's not once you get the basic function in of player comes in, picks up item, sells it, it's just the same the like reskin thing put all over the shop with a few different like modifiers that are that are different or variables, whatever you want to call.
James: Yeah. But also once you start to really dive into a lot of this, you know, game frameworks and modularity and understanding how the code actually works and when's the best use cases, et cetera, you'll see a lot of the games are just la all they're all like that. It's just a matter of scale and scope, right? Like what's the difference between the shop simulator game where you have that on interactive where I can pick up stuff and then I'm holding something? Right. So your on interact message could simply be I'm interacting with you. Here's the object I'm holding. If I'm not holding anything, it just doesn't pass you anything, and you do your code anyways. If I am holding something, you can tell the shelf to see that I'm holding something and then grab it. I own that now, it's gonna pop into the shelf, or we just teleport it or whatever. Right. What's the difference between that and vampire survivors? Right? Think about it. Once you have the logic set up for my projectile, my spell, whatever it is, on touch is the same thing as on interact.
Spencer: Yeah.
James: I hurt you. I hurt you. I hurt you died. Once that's set up, every single enemy.
Spencer: I guess that's fair. It r like once you get that basic stuff, it's just like game design from there.
James: Yeah, once that is properly set up on a technical foundation, in the vampire sense, it's the exact it's very similar to your shop example, right? Where every single item in your shop is
essentially the same code with a different skin, different audio, right? Every single enemy in vampire survivors is essentially the same enemy with a different skin, different effect, right? Different attributes,
Spencer: Yeah.
James: sure, but like the interaction of the code. The systems. Once that's done, it's done. Like there's no
Spencer: arguably then it's Elden Ring, I guess you could even say the same kind of thing. It's just a bunch of different enemies with or the it's maybe it's the same enemy with just like different size, different animation and it's holding a different weapon.
James: Well, I wouldn't say that about the anime types, because there's a ton that goes into that kind of stuff. All
Spencer: I guess that's fair.
James: right. But but where that could still apply is in the weapon design. Every weapon has poise, every weapon has all the attributes. It's a very complicated system. They all have animation sets, they all have certain ways of calculating overlap and collision volumes and all that kind of stuff, right? And the damage is a volume contain volume overlap. So it is on collision, right? On overlap. We do damage to you. I could talk about that for a while. So I'll stop there, right? Like that interaction is the same for all weapons. It's the same for all spells. You launch out a ice bolt, it has a little sphere on it. So when it flies at the target, if it overlaps, it does on overlap, which is like, here's the damage I did to you. Here's my here's my attributes as a spell. as an arrow, as a sword, run your modifiers. So if you're an ice mage, you took less damage. If you're a fire mage, not that Elden Ring works that way, but it's very easy on the enemy logic side to do the damage calculation. We're just feeding it the like this is what this bolt or this weapon is made of. I've touched you. On touch, take this information and do what you're supposed to do. Right. That's very easy. Once that system is working, yes, every boss, every system, every enemy, every object in the game world can use that. Every hidden illusion door that you have to overlap to hit to reveal that secret passageway is probably using the same kind of system where we're just detecting on overlap. on overlap with weapon type or weapon category, right? That interface message. I'm supposed to do something. Well, as a secret door, what I'm supposed to do. Is not exist anymore. So I'm just gonna fade away, right?
Spencer: Yeah.
James: But that interaction I'm getting at, that system that you pointed out, is the same all the way through, right? Your character specific stuff, bosses and stuff, that's gonna be more bespoke. But the interaction of weapons is all the same. All of the big enemy boss types and their weapon swings and their big spells that crash down into the world, they all work the same way, right? Because that's the combat system. So when you design it modularly that way, Elder Ring is a great example of seeing just how much depth you can get
out of a system like that without a ton of rework. I mean, there was probably a ton of tweaking, right? Adjusting and iterating, but they probably didn't have to go back through that system many times because once it worked and it worked well, there was no reason to go back and change it. Right. So so that's the whole point of this episode is learning these techniques with how this code communicates. So you can design that kind of interaction. So you can design those kinds of behaviors. Anywho.
Spencer: That's great. I think we found our clip that's going at the start of the episode.
James: That's good. That's good. yeah. So that was interfaces, dispatch delegates. What is my next one here? persistent objects and subsystems. So this is like the advanced level of code communication and it's kinda global managers, right? It's stuff that is always there. It's your game instances, it's your game states, player states, stuff like that. That's the same level. And you can make those, right? A lot of a lot of people especially when they're new to Unreal or any of the game engines, they don't understand that you can make that kind of persistent data that transfers across levels or playthroughs or saves and stuff like that. so yeah, like what are they? They're global hubs used to store data and handle the communication across the entire game. So again, game instance, game state, game mode in Unreal are all examples of Permanent, excuse me, not permanent, persistent object and a subsystem. So they're just always there. So it's okay to cast to them. I want to bring that back. So if you create a custom subsystem, it's okay to cast to that subsystem because it always exists, it's always loaded. So this is where they again they can kind of come together. So it's kind of a modern shift. Right in the game system design, what not yada yada, right? Subsystems. So rather than stuffing all of your code into a bloated game instance, and if you are a old enough game developer, you will have heard or seen plenty of scripts from people. Where the entire game is inside of one character script, right? Or or things where it's like the game instance holds every bit of logic in the game except for player input. And a lot of Java and like older web games and stuff were made that way because why not, I guess, right? but that's bad for a lot of reasons. That should be pretty obvious. Right. but right. so yeah. So rather than doing that and stuffing it all into this bloated massive file, right? Unreal 5 specifically, well, Unreal, heavily utilizes subsystems and they're modular managers that automatically instance themselves. So it's it's they inherit from the game instance, which is how they work that way. but it's stuff for like your inventory management, stats, any kind of custom data, right? So A good example of this, and I don't know if they do this, so you know, don't quote me on it. But Tarkov has a really interesting weapon system where it's like the physics and the attributes of like per bullet is transferred per bullet on interaction and stuff. That's that's a lot of data to to store and load and everything else, but that's also a good candidate for a subsystem. You always need that stuff readily available, so having it a part of a weapon subsystem where it's just tracking all the data from projectiles makes it really easy for anybody to be hit by a bullet and then just talk to the thing that already exists and say, what kind of bullet was that? What are its variables that I need to care about? And then I could process that really quickly. Versus if I tried to send that through a network packet, right? Where it's like I hit you and here's 20 things you have to learn about. That's a lot of data to send through a network. But in a subsystem, it exists on everybody's computer. And it's run by the server. So I can get hit by a bullet, not care what it is, other than its name, and then I can use my own computer as a client and go look at that subsystem and say, that's what I got hit with. I'm gonna do my calculations now. So that's how you can make really
Spencer: So if we were making a sp a space game, then like the like all all of like the f the flight subsystem where it like has like thrust and velocity and like the the mic the the mechanics of like how a a ship flies is something that could be a subsystem so that any vehicle that's moving through space would just references that for how it's gonna interact with or not interact with things, but like how it moves around.
James: I think there's some confusion there with just like the way subsystem is used and like fiction and and whatnot. But a better a
Spencer: What Okay.
James: better more not better, but like I guess a more accurate way to describe that would be like a subsystem for how 3D traversal in the space game works, depending on the system you're in. So if you're in a system with lots
Spencer: Okay, yeah.
James: of planets and they all have their own rules that affect how How the game is working, you can have that as a subsystem. So at any point in time when your ship is trying to fly forward, it can talk to that subsystem to understand, I'm actually supposed to have a bit of turbulence. So I know my logic for turbulence based off of, I don't know, custom components that the player has equipped on the ship. But I don't need to calculate what that turbulence is supposed to be based off of objects around me. The subsystem does that. The subsystem knows when two stars are close together that the field of gravity should warp in a certain way. You can tell the subsystem, Hey, when we're orbiting a black hole, we're permanently sucking all objects into the center. And so it becomes a game like that subsystem manages the rules that are always like outside the bubble of the ship. Right. So the ship has to react according to the rules of the universe. And the universe is the subsystem.
Spencer: Okay. Cool. Yeah that makes a lot more sense then.
James: Yeah,
you were almost there. You're almost there. But that's why I said I think there's confusion there with the science fiction side, 'cause I've heard that from other people, might not like that, but
Spencer: Well I the where it came from is like in the Godot project I'm working on, I have this little drone that flies around. And I created like a global script so that any like any other object I decide to put in that I want to be able to float around, it has its global script that it references for like the the ma like the mechanics of like how it can move around and and shift and stuff. So maybe I was just mixing up. I don't know. I guess I'm still trying to figure out the the relation between the stuff and like in Godot.
James: Yeah, there is there's some interesting stuff there. trying to figure out how to parse that, right? but yeah, like the global variables, they're not quite there, but it's the same kind of idea, right? Like this is something that's always there. It always exists, it has persistence. Where and what you have in the subsystem is what's important. So a subsystem shouldn't cast to anything that's not also persistent because that that follows the rules of our direct casting that we talked about. Right. And we d like we don't want this in your example, this solar system, right? We don't want that subsystem to ever cast to anything inside the system it's managing. We don't want it to talk
Spencer: It's like
James: to the shit.
Spencer: it should display information that other stuff grabs from, but it should never grab stuff from other things.
James: Right. Yeah. So that's exactly right. So you're direct casting, right? It would be okay in that instance for your ship to do a direct cast to your solar system subsystem to find out what's the gravity that I am currently in, location based, if you're doing something that has like spatial awareness, right? What are the current, what's the radiation level, what's the light level, what's the hostility level? All those different things, right? When you think about let's use Eve as an example because it's pretty comparable. When you think about when you scan a sector and you want to see what's its economy value, its piracy rating, and like all the different different attributes, what kind of minerals are inside that's that instance.
Spencer: So it's like a subsystem, it more of a list of information.
James: Yes, and also information that's processed, right? So a subsystem could be something that manages water or manages fire, right? Wind, textures, seasons, because that stuff needs to always exist. You can't just not, you know, it can't not happen. So you could put that in a subsystem so it's always taking, right?
Spencer: So then before we were doing or before we started recording this, we were talking a little bit about like Minecraft's water physics. Or no, maybe not physics, but like how Minecraft does its water. Would that be like a subsystem?
James: Yeah. So the subsystem, what the subsystem could do, right, is manage the simulation process. Where does water exist in the game world? Where does it not exist? Depending on how you do it, right? and whenever we need the water to react, the subsystem does that, which is why we can leave and come back and the water didn't disappear or didn't change. Or it continued to change. Right. If you done that where you're like, I'm gonna dig out the spot, run away, come back because I don't want to wait for it to fill in. It's the subsystem that continues to process that even though you're not there. Right. And this is like the other side of why the subsystems are really powerful, is that they're not spatially bound. Right. If you go far enough away or you look away, depending on what kind of object class or you know, object-oriented code you're doing. It stops existing. Nothing's going to tick anymore. It's just going to disappear. Right. So if you're if you're if you have a trap and it's a time delay and you hit the trap and then you very quickly teleport 600, you know, a thousand units in the other direction. And it's far enough away for the game engine to say this isn't relevant anymore, according to everything that we need to render for the player, I'm going to unload or get rid of that barrel. And if you come back and that barrel is still there and hasn't blown up yet, that's something that is not persistent, right? It's only relevant because it was relevant to the player in that moment. So the subsystem is doesn't care about that. If you trigger that bomb and you teleported 10,000 units away, it's gonna be paying attention to that and say, Nope, that blew up. So when you go back, there's just a scorch mark on the ground and some loot or whatever debris. Because the subsystem knows That was supposed to be destroyed. So I'm gonna destroy it. Okay, it's destroyed in my internal ledger of all the traps, right? I have a trap subsystem just for argument's sake. It knows what has exploded, what hasn't, what has done what where, how much ammo is in each trap, how much like all those calculations. Yeah,
Spencer: That gets complicated.
James: right. but that's also why it inherits from the the game instance subsystem. Right, is because you're you're meant to use it to track global information, global data. Anything that needs to process and should always process, regardless of whether or not something is looking for it or asking for information, speaking to it, that should be a subsystem. And if you build it as a subsystem, that'll save you more re resources in the long run than it would be. to try and develop a complicated trap manager blueprint that is actively casting or even has delegates to manage all these different kinds of traps and things throughout your dungeon, right? Because that's a lot of work. That's a lot of work to make sure everything is managed. And then you're gonna run into those educations, like I said, you procedurally generated a level and you went all the way down to
the end to flick the switch and you came all the way back to the boss and then like nothing's why didn't the door load get that switch, what's going on? And when I go back to that switch, it's fli it it looks like it's like change position. What's going on? The door probably unloaded because you got far enough away where it lost relevance. And so your code is still working, but the object that's listening for that that broadcast doesn't exist anymore. So it's not going to register.
Spencer: It's far enough away that by the time you go back to the switch, the door is unloaded. When you get to the door, the switch is unloaded.
James: Yeah, and that's something that can happen, right? Especially in procedural situations. that that's a that's an example of where the broadcast system is not perfect, or the dispatch event dispatcher. So you kind of have to understand all the nuances of these different, like I would say, communication archetypes, right, for code and how they all work, because they all have a specific use case, right?
Spencer: Yeah. Yeah, because having an understanding of all the different ones means that you'll be able to use them in different situations and you won't find yourself in a stuck in something where, like, for example, we have that door and switch that are too far away from each other. And so if if I only know about the listen and the and the and the receive, then it's like, okay, well, now I've got to build another system so that when it sends it out, it's like it's now stored somewhere so that if the door doesn't node. or isn't there then when it loads back in versus being able to use other things that might be able to just bridge that connection without it.
James: And and honestly, this is where a lot of the spaghetti code, right? We talked about that very early, is like, do
Spencer: Okay.
James: a lot like do we see that a lot? That's a big reason why we see that a lot is people are they get far enough in their game, they're starting to get more into the scope creep and like they have content and they're trying to hook it all up and then things aren't loading properly. So the only way to make it work is to do a direct cast, and it's the only thing that works. It's not the only thing that works. It's just what worked in that situation for you because what you're trying to do probably didn't shouldn't be a direct cast. Maybe it could be a delegate, right? or a dispatch. Maybe it could be it could just be an interface, right? Like on interact, right? Maybe it could be a subsystem because you're trying to keep track of a ton of data and you don't need to care where it is in the world. You just need to know what the data is supposed to be. Right. So something else can read that data and make decisions. So like knowing that relationship, yeah, super important. And a lot of novices don't understand the difference. They don't really understand the big picture. They go through a small game jam doing all purely casts and decide,
this works fine. Yes, for a game
Spencer: Yeah.
James: jam. Right. But once you get a year or two into development and then things are breaking and you can't figure out why this complex system isn't working right, you can't figure out why you changed one component and like a bunch
Spencer: Yeah.
James: of stuff broke. And you know, some of the worst examples I've seen are when people put a bunch of stuff in one like a dispatch or like one subsystem, or they think that if I just have one master manager who knows everything. I'm gonna be able to put all my functions in there, whether, or an interface system, everything goes through this one interaction component. And if everything has the one interaction component, everything in my game works. theoretically,
Spencer: Yeah.
James: sure. If you're in a small arena or or like a very linear game, sure, I could see why you would come to that conclusion. But but something breaks, and specifically interfaces, they're they're tricky because they don't tell you what's wrong. Now you have to go look through your interface. And if you have a bunch of functions in there, and I've seen this on quite a few projects, where it's like, okay, which which of these interfaces functions didn't work right? It's like, I don't know, because they're not relevant, they're not split up. Right. So so it's it's okay to have multiple interfaces. It's okay to have multiple event dispatchers. It's okay to have multiple subsystems to keep different categories of data separate because it's easier to manage. yeah, so so again, subsystems are all about persistent data, what needs to always exist, right? And you when you're thinking about how to design the interactions and the code, a great example of that could be let's see here like corruption. Let's say we're in a dungeon, right? Sticking with that example. The longer you're in the dungeon, The more corruption there is in the dungeon. It's like my miasma, fills up the dungeon. So your cis, your subsystem keeps track of how much that subs like data is changing. And so you can give it specific code to say, well, here's some spawners in the world that the subsystem listens to to increase miasma in that area. And it just slowly permeates like a 3D grid where the biggest concentration of that corruption is. So as you're running through the dungeon and it's filling up with gas, it's not just like a plane that live levels up. you could literally create a volume that is managed and calculated and has density and whatever else through the subsystem. Now, your doors, your objects, your loot, maybe your enemy types actually get stronger with corruption, and you want to create an interesting dynamic so that the longer you take in the dungeon, the more difficult it gets. That's really easy to do because your care your enemy types. Interact through an interface with your weapons, right? I hit you with the sword, you were hit. So your interface is going to tell you I hit you with a sword, you're
going to do your damage. But while you're doing your damage, you're going to cast to my custom subsystem to see how much corruption is in the local area around you, and then do modifiers to show how much damage you actually took. Right. And all of that is modular. Right. And you can the subsystem can communicate with anything that you want. It sorry, it doesn't communicate, but it shares information with anything you want. So your chests, your loot, maybe the you have multiple dynamics there. Maybe you want the combat to be harder. So your enemy types listen to the subsystem for like boosts and attributes, but your loot and your chest actually degrade in quality with the more corruption. Both of those just direct cast to the subsystem. It's always there. Costs zero RAM, right? There's no no heavy footprint there. It just says how much corruption is there? okay. I'm gonna look at my loot table, my personal code, and see, okay, this is the value of corruption. This is what I'm supposed to do. This is how it applies. Here's my corruption multiplier times my damage input or resistance, excuse me. That's how much damage I actually took, right? So very quickly you can create a system around corruption. Fear, fuel, dark matter, like gravity, it could be anything, water, fire, physics, right? Everything can speak to that and make decisions on their own of what they're supposed to know based off that data. So that's kind of like how the
Spencer: So then two
James: systems can interact.
Spencer: I got two questions with subsystems then. I is a subsystem something that is just infinitely persistent within the game? Or is it something is it where it's like if I load into a specific level, it could have its own subsystems that in a different that a different level wouldn't have?
James: Bit of both. So you can set them.
Spencer: 'Cause if if we have that subsystem for corruption and it's only something that happens in the dungeons, is that is that just a subsystem that's always just like in the background where it's like, Well, I'm not in a dungeon, so I'm just not gonna do anything right now?
James: You can code it that way, right? You you could set a flag that just says, Are you active right now? And then when you load into a level, the level blueprint speaks to the subsystem and says, This is not a dungeon, according to the designer. You turn off. Now
Spencer: Okay.
James: you're now your subsystem says, I don't need to tick, right? I don't need to have a function where I'm counting every second or every frame, different changes. So I don't need to I don't need I don't need to be active. I could just turn off. So you can save resources that way, right? It's still there. It's always there. But whether or not it's doing anything is what you can control.
Spencer: And then if I had let's say, continuing with that corruption subsystem, if we had say say it's like a multiplayer game and we have it so that we want it so that the more players that are in the dungeon, the faster the corruption builds up. Is this something where like we can have other stuff send information to the subsystem where it's just like If I know, we've kill every time we kill an enemy, we say that we tell the subsystem to just tick up this one counter on it, or if the more players are in it, the the players say like, Hey, add another number to this. So it's is it okay for us to to change modifiers or s or variables in a subsystem?
James: Yeah, yeah, of course, right? You could you could
Spencer: But we just can't we just don't want the subsystem to be asking, Hey player, the you know, we want the player to be saying, add this subsystem.
James: Yeah, there's th there's two things there. You are allowed to ask the subsystem for information. You Aren't asking the subsystem to tell something else to do something. Right. And you're not trying to tell it, hey, here's your information. It has to be one way where you're only asking what's the data that you currently hold. Right. And if there is a situation where you want to modify a variable, like for example, for every enemy defeated, we increase difficulty, or maybe we just lower. Maybe that's a different, maybe that's a mechanic that makes it a little better. We lower corruption by a set amount. So you could do that. So every time an enemy dies, you cast to the subsystem. Sure, right? That could be it. Or you could do it through a delegate, right? So your subsystem, you create an event dispatch that says, let's say Reduce corruption. That's just what it's called. Just reduce corruption. And then you give it an input type of float or integer. Right? Integers better. It's better to calculate, but so we'll stick with that.
Spencer: And then just 'cause I'm still trying to remember the differences of this. An integer is like a set number and then a float can be like a decimal point. Okay.
James: Yeah. So floats can be bad because they wander. It's the finite data when you're like one point zero zero zero one does not always stay one point zero zero zero one. It could be one and then randomly it gets truncated to one. But depending on how your float is used, that point zero zero zero one could be very important, right? If you're For example, if you're using a float to determine seed generation, that discrepancy could be the depending on your system, that could be the difference between a two story building or a three story building. And that could that's a big difference, right? So integers are better to use in those s scenarios. Cause you don't want to have like anytime you need data to be perfectly communicated and to be modified, you should use integers or at most like a double, right? So it's like a one point One, right? it's it's capped. That's primarily when you want to use that. When you're just using something that has to deal with really low numbers that are constantly fluctuating and changing, it's okay to use floats because you don't actually care about those micro decimal
numbers. They're just there to like have representation. That's okay, right? So so yeah, so the way you would do that is you'd you'd create the event dispatch, right? The publishing event on your subsystem. Sorry, you're I got the background. You're listening on the subsystem. And then on your enemies, you would do your publishing where you say, I died, right? So I died. I'm going to trigger this event. And so on your subsystem, you just loop through every single reference to the types that you care about. So I would not do like every subclass of enemy, but I would cast to the master class, right? Your book clear enemy master. On there, you have your delegate for on died. And your subsystem is going to listen to that. And it's going to s you could assign a value to that too for each subclass. it's an elite monster. Maybe you want it sp to do three instead of one as an integer value. Your subsystem will just listen automatically every time an enemy is killed. Find out its value that you have assigned it on per blueprint and just subtract it from its construction value automatically. Once you've set that relationship up, it doesn't change. What's nice about doing that as a delegate versus a interface is that you could apply that to anything now, right? That same kind
Spencer: You mean versus a cast?
James: of listening. This this is the event dispatch.
Spencer: Okay, okay.
James: Right? You're broadcasting. You could have the same.
Spencer: And then what's the interface part of that again?
James: The interface would be I'm hitting the enemy with a weapon. So I like
Spencer: okay.
James: on hit, I did damage to you. You died. You're gonna broadcast you died, and you're gonna say your value for corruption, right? Once that's shouted out into the ether, the subsystem is just be I know what that means. Click, and it's just gonna de increment, right? You tell your subsystem, you give it the code to listen to that integer value and just reduce your val your corruption meter by that value. And it'll it'll automatically do that every time an enemy dies. And so having that set up specifically that way means that in a multiplayer setting, any enemy that dies anywhere is just gonna automatically reduce your corruption setting. So it so it doesn't have to be on hit, right? On death through an interface, we're going to directly interface to your subsystem. Because in terms of design, now you've opened up the ability to have Enemies that die not directly from player involvement contribute to the system too. And that's where it gets interesting because now you can have a more modularity. You could have a lot more freeform in freeform design in how you kill enemies. Maybe they maybe there's physics in your game where you have a big heavy boulder and you want to be able to allow the archers or the mage classes to hit the plank and it drops the boulder onto like the big heavy enemy units as like a clever, like, I didn't think the devs would. That in moment. And they
died. We don't care how they died. The fact that they died, the subsystem already knows, registers, and reacts accordingly. Right. That kind of interaction makes players feel really smart. And it's fun because now what else can I do? What else can I trigger? Right. And so that system of like managing your corruption becomes modulous. It's modular because your subsystem is listening to whatever is important in your game world. It knows how to manage the data. And then your enemy types will ask your subsystem, hey, hey, you, what's our current corruption in this room? I'm gonna take that data and I'm gonna beef my stats accordingly, which to the player it could just be red eyes, right? It doesn't really matter, right? What matters is that. On hit with the weapon or the spell overlap, we're going to get that information from our subsystem. Say our corruption value is really, really high. That means I have a high defensive modifier. I'm going to take less damage as an enemy type. And that's modular from room to room based off of the corruption in those relevant areas. Having that generic delegate for your corruption, I said, like reduced corruption. The reason I named it that way is because maybe.
Spencer: You can use it on anything.
James: We can use it in anything. Exactly. We can create a separate event on I don't know a a a a holy relic that you can find in the dungeon. When you interact with it, it reduces the corruption by like twenty percent or some other value or like ten units.
Spencer: Yeah, or if there's a mushroom and every time a player pees on it it reduces corruption too and it grows a little bigger. Thanks, Kojima.
James: Yeah, right. And and so right away, I I saw that moment where you're like, we can put that on anything. Yeah. And now you can add so much depth to your design, but how much code did we like theoretically, how much code did it take to get that extra level of depth?
Spencer: Just took that one piece of code.
James: Took the one piece of code, right? Proper communication. Now, if we were to really take this a step further the way I would like with the client, that would be modifying corruption. 'Cause now you can take the same delegate and literally apply it to anything so it can positively affect corruption or negatively affect corruption.
Spencer: Because it's just a positive or negative number.
James: Yeah. But the reason you name it onModify is because now you're not creating multiple functions, right?
Spencer: Yeah.
James: Talking about spaghetti code, right? You just have the one generic name. You code it to be modular to work in both instances. And now when you set up your delegates or your interfaces, your direct casts, however you want to do it, you just have that one function. And then if you
Spencer: Yeah.
James: want it to be positive, give it a negative number. Right. We're passing you a negative number and the code subtracts whatever number we have from our total. Right. And then so right away you here's this big complicated system, but it's really not that complicated.
Spencer: Yeah, there's so much of this that really comes down, like whether it's deciding if we're gonna cast or if we're gonna shout and have something listen or or any of this, it it's just another thing where a really important question to always be asking before deciding it's done is what am I using this for now? What am I gonna possibly use it for later? And how what kind what am I gonna want to be able to interact with it? And then that dictates how we wanna go with the way that we communicate the the information as well as how we're gonna be implementing it.
James: Yeah, a hundred percent.
Spencer: This is so much fun. I love making games. Although
James: So so
Spencer: although it some of the stuff kind of there's it kind of ruins a little bit of games too, because there's certain things
James: Sometimes.
Spencer: that like there's certain games that like schedule one. I went back to go and play some of that, and now there's certain things where I just can't stop I can't help myself but think like, okay, I see how they do this and I see how this works with that and Or at least I d I don't know for sure. I'm just guessing. But it it it like it takes away the some of the the immersion of how I used to be able to get lost in some of these games. But at the same time, just
James: Yeah.
Spencer: making them is so much fun.
James: Yeah, yeah. yeah, and it so, you know, that's that's like
Spencer: Sorry, that was a little off.
James: all the basic communication stuff, how it all works, why it's important, how it impacts things. And you know, I I it's like callback to like some a couple episodes ago, like we're talking about toy box, right? This is now that we have a broader understanding of communication. modularity, how certain design decisions and technical decisions can easily create a ton of bloat, right? A ton of scope creep, or it can make a very modular system that you can get some really interesting gameplay out of, right? Looking back at those.
Spencer: that's true. Cause sorry to interrupt here, but so scope creep isn't just about like adding extra functions to scope creep is also, you know, take like how many times am I gonna put the same a re like put the same function in other things in different ways.
James: Yeah, right. It's scope creep in your code. Right. And
Spencer: Yeah.
James: yeah, so like it it it all comes full circle. It's all the same. And I lost my point there. I was gonna touch on
Spencer: Sorry, James.
James: no, no, it's okay. What was I talking about? it's gonna drive me nuts. It's been a long day. Anyway, yeah, so like the code, the interaction, the subsystems, modularity, blah blah blah. Toy boxes. That's where I was at. Toy box. If you recall. I'm not really a big fan of Toy Box. I think
Spencer: Mm-hmm.
James: Toy Box is great to hop into an idea. It's great for game jams. It's great for when you, your team has extra time and you're like,
everybody, go away for a week and go nuts and make weird wacky ideas and like it doesn't matter. Like we're just looking for stuff that's cool. Right? That's that's great. That's perfect for toy box. Right?
Spencer: Yeah. I love Toy Box.
James: Toy box is so much fun. You you just just You're like, what about this? Right. But as I talked about, Toy Box is bad because if you don't understand all this other stuff about like your communication and your code and modularity and pr and design and how like your decisions work together, right? Design isn't just about like I made the game rules. It's understanding how it transfers to code, right? And all the other departments. If you don't have that foundation or at least a basic understanding of it. It's way too easy to get carried away. And then all of a sudden you just toy boxed a ton of stuff and then you're not gonna get anywhere. And you will see that all the time on YouTube. I like every day I get recommended new devs and I go check out their stuff like when I have time or I'm just putting stuff on the background. They're always like, Yeah, I got so far and I had to restart. Stories are always the same. It's like I did a bunch of stuff and then I couldn't figure out how to do it, or it didn't feel good, or you know, something got to a point where there was too much. And it was too much to handle, it was too much to fix. So I'm just gonna pull back. I'm here's version 2.0, and it's like super stripped down. And it's like, yeah, a lot of the ideas were really cool, but because you didn't architect it, right? You didn't design it to fulfill those needs, you just kinda tossed stuff in that was fun in the moment, it became really hard to deal with do anything with it because the moment you need to do something other than what you were toy boxing with, that's where toy box fails, right? Because you're not thinking about the ways that you're not playing with it. You're only thinking about how you're playing with it. So toy box is good for ideation, but once that's done, you really have to stop like a week at most, I would say, is like that's your time to prototype and tinker and have fun ideas. And then afterwards take a moment.
Spencer: when you say a week I I'm sure you're talking about a week of full time work on.
James: Not even, right? E e even just part time work. you're a hobbyist at home, you're like tinkering.
Spencer: Well I I guess that's fair.
James: Well, ca because here's the thing. You benefit from having me, right? And explaining a lot of stuff that you're getting the references and same with other people who are listening here, right? Like you're getting that context very quickly. Whereas if you're just a new developer and you go to YouTube and Indie Innovators is hidden because we're new and none of you are sharing us, so shame. A joke, a joke. Thank you for being here. But right, like You don't have access to the people who are explaining it in this way. And I'm not the only one. There's lots of people trying to do this, like you and I, what we're doing. But we're just not very interesting. it's technical. It's dry. A lot of people are like, I just want to get in and do some cool stuff. So they gravitate to that content first and they miss out on all that context. And so they just toy box and jam stuff together. And then they can never figure out why is my games always bad? I'm on my fourth game. I'm I Forget there was, I forget the name of the studio, but it was like an indie team, right? It was one guy, two guys. But they're on our like third or fourth game because they keep like getting to a point where they're like, Man, this just we're not getting funding, it's not fun. We hate this. We're gonna go back to the drawing board, and here's a different idea. Because obviously, we can't do that other idea. And I'm like, man, that sucks because some of those ideas had real potential. It's just you fell into a gap of not knowing. And not having access to the resources to learn what you don't know. And then you're just on your third game, your fourth game. I'm quitting game development because this has six years of my life and I'm not going anywhere. It's like, well, yes, because game dev is software development, it's use it's it's a very complicated industry. You need more than just game design and code and art. Right? That's that's a big thing I I I see all the time talking with like newcomers, students. Other indies people I'm working with where they just have this perspective of I'm not gonna consider things outside of my game concept and not realizing that it's it's just one pillar holding up like the potential of your studio and like that you you can't balance like this, right? It's really hard.
Spencer: Ha ha ha.
James: And that's what they're all struggling from is they're like, my God. And then even if they do make it, and this is another thing you can track, just look at Steam. At all the indie titles that have made it. And then how many of them faded out, only support the one game, never made anything new? How many of them went on to make two or three more games and
Spencer: Yeah, so many of them only have one game.
James: they're bad? Or they're just not as good as the first one, right? Well, the reason was is this managed to work for them, and then now they're building the second layer of the same thing on top in this wobbly pyramid, and that's crazy hard to do. Right. So you have to build a solid foundation first. And I I I do not agree with anybody who tells you on the internet or in person that no, making games is just about throwing stuff together and find the fun. Finding fun is important. But
Spencer: if some people are just extremely talented and that just throwing together
James: Yeah, but yeah, no.
Spencer: works for every time.
James: Name one.
Spencer: we can't all we can't all be those really talented people.
James: But but but name one, name one.
Spencer: I don't know enough about that stuff, but I
mean like there's there's a lot of people where they they're just
James: that's a cop up.
Spencer: fantastic painters where they just throw a canvas up and they come with no idea of what they're gonna do and they just paint masterpieces. And I I'm sure there's game developers that can do the same thing, but that's like a very small minority of like the less than one percent.
James: That takes a long time though, right? You think about all the great talented people that fall into the category you just described. Most of those people
Spencer: I'll be one of them.
James: most of those people though were never recognized for any other talent until centuries after they died. Because it took centuries for that skill and that understanding and stuff to be s to be understood. Now it doesn't take centuries anymore. But it could take you a whole career of just, I'm gonna power through like this because I'm amazing. And the way things go in our modern world, that's just not gonna happen. Like you need a good foundation because it's not enough to make beautiful art anymore, right? You can't just make a great game and it's gonna succeed and you're gonna become wealthy and famous. That's not how it works, right? Stardew Valley is one that's brought up all the time as an example in all my all the dev circles I'm in. And I'm like, yes, sure. Credit where credit is due. That took a ton of work. It took a ton of dedication. It took over a decade.
Spencer: But they also got in really early.
James: They got in really early. There was nothing on the market that really compared. you know, like there's a lot of reasons why that situation worked out. But where's the follow up game? Where's the follow up studio? Where's he's still working on it? And that's that's not a dig, right? It's it's not a dig on it.
Spencer: He's still working on it. But then goes back to work on starter instead. No, no, it's not a dig, it's just funny.
James: But I wanna point out that contrast, right? Like a lot of people are like, talent. Yes, talent, absolutely. But understand that that's what talent looks like. That's what being lucky at the right time with the right things and the right just it just clicked. It just happened to click. And that's the way it went. Right. There's a difference between Stardust Valley and let's say Phasmophobia. They're a good example. They just start they s recently started up a whole publishing firm that's supporting other indie titles. Like they got they got
Spencer: That's awesome.
James: lucky. They built a system and then they built off another company that's b you know using similar I imagine similar business systems and whatever else they're doing to try and prop up other indies. Like they're scaling and growing. They did luck have an element of luck over time. They did work on their game, they did the updates, they attracted the crowd, they did all the right stuff over time, but they have such a solid foundation, they're now able to scale and grow. Right. And that's what that's what I'm about. I want to see people grow. I don't want you to just make your first game. I want you to understand the complexities of making a game so that you can make your third game, your fourth game, your fifth game.
Spencer: Well, because I guess it's a little different for me right now because most of my like I love toy boxing, but it's also just because I'm learning the system and trying things out. But through the our conversations, there's not a single thing that I've put in where I haven't thought to myself, How do I make this its own separate like how do I contain it into its own thing so that if I'm making something else, any part of this I can like take and then use it elsewhere. So But I it's also it it's mostly just been a learning thing. So that's why I've really enjoyed Toy Box right now.
James: Well, toy toy box is good. That that's why I'm glad we dedicated that episode to just talking about it because it does have its place. It is very valuable. I'm not trying to shit on it. But I think if you're trying to build a future off of toy box, you're in for a bad time. Because it's that's that's that's crazy. That's it's like hiking out into the woods with a stick and being like, I'm gonna rough it versus heading out with
Spencer: Ha ha ha.
James: First aid kit, a camping set, a tent, like you could do it prepared or you could wing it. But if you're gonna wing it and things aren't working out and it's difficult, you that's what you chose. It's what you get. It's what you get. But to be fair, a lot of times people don't know that there is a different option. So anyway. so yeah, like I I think another kind of more back on topic, when it comes to like communication. One that's big in modern engines and this Godot, Unity, Unreal and Sabral of the other like derivative stuff that's coming out now. blueprints or visual scripting versus C plus plus architecture, like that how you go about building your games. So the rule of thumb is that your hard code, C plus plus, C sharp, stuff like that, it should be heavy lifting. It's it's your base classes. Like I mentioned earlier, your enemy master type, right? Or your hero, hero master, or like objects master, interactable, etc. Those classes should really be C or code based because they do all the hard calculations. It's the way they're supposed to be. They're supposed to have all the heavy data. All of your child blueprints are for the little stuff. I want this this blueprint to have this match. And play this sound and play this animation and be customized. Like that's where the designers live, right? It's in that part, but all the code that makes it work, it's better if it isn't C. Just hands down. and and complex math should be in there. You shouldn't be doing any complex math in blueprints. You can, you can. Full games have done it and have gone live and they still have good performance. I'm not saying it's impossible, but I'm just saying, brass tacks. Yeah,
blueprints should not do complicated math. they're for design, they're for iteration, they're for visual tweaking, they're for the custom little like I wanna I wanna play this game and here's the jump meter
Spencer: Okay.
James: my jump float for how strong my jump is. I didn't like that. I'm gonna I'm gonna tweak that value. I'm gonna try again. I didn't like that value. I didn't tweak that again.
Spencer: So is it like the code like the C plus plus in the code would be something like the audio playback manager, for example. And then the blueprints would be I'm gonna connect, I'm gonna have this object play this sound when this happens.
James: At this volume with this frequency and this other pitch information, because that's all exposed from code. My blueprint doesn't know what to do with those. It's the code, my my hard code, that understands how all those things work together, but we expose them as variables in the blueprint. So it would be okay.
Spencer: So that that way the blueprint you set it's it's like a a simple visual thing where you just put in the little bits of information and then the blueprint basically you know d sends it to the code for the code to to do stuff with it. I don't know if that's the right way of saying it, but or it's like the code's
James: It's a good way to think about it.
Spencer: hidden behind the scenes in the blueprint or something like that. I don't know, I don't really know how blueprints work, so
James: Yeah, well it it it's a different way to think about it is a container. Your blueprint is a container for all the stuff that your code can do modular things with. So you wanna change volumes, statistics, armor rating, armor resistance. You wanna like do small calculations like if I'm overlapping with this object, it's actually a minus five instead of a plus five. Like stuff like that is perfectly fine in blueprints, and that's where it should be because the core logic of how the math is calculated is done in code. The blueprint doesn't do that. The blueprint just changes what those variables are. And then you can create multiple blueprints that have different combinations of attributes. Right. Like your warrior versus your mage really, apart from having flags that say, you can't hold two handed weapons and you can't hold staffs, like that's a it's literally a bool, right? Like a true false in most cases. And other than that, it's warriors have
Spencer: Yeah.
James: more health, warriors have more strength, mages have more intelligence, more wisdom, etc. And those variables are just custom set in each of the blueprints. But the core system that manages your attributes and what that means for all the different kinds of calculations should be in code because it's faster. It it's just
Spencer: So then from everything we've talked about today, the health and the core idea of like what like the basics of what a class would be would be like a subsystem. Or not like a class, but like, or maybe so, but like the subsystem would be like this is health, and there's all the other stuff. And then you would have your whatever code or scripts for like the diff for the subclasses, and then am I am I Am I f following this r is am I going weird with this?
James: So what I think what the best studios do is they put all of their core functionality, like interfaces, structs, your base classes, all the math, all of the, you know, when I take damage, what do I need to reference? I need to look at my attributes, get all that data, run my calculations, all that kind of stuff should be in code, right? C plus plus, C sharp, whatever. And then your blueprint, your child classes from those, because here's the other part. I I am surprised how often I hear is that you can create a blueprint child from C code. So it inherits all the logic from the C. It knows what to do, but we're not letting the blueprint have access to change any of those formulas, is how it works. We're just changing the variables. Yeah.
Spencer: Okay.
James: So your Blueprint classes are for your designers to create your event dispatchers. We want to cast to nodes and we want specific things to happen, right? Like that should be in blueprints. Or we want to swap out meshes or visual things without touching the code. We don't want to go into C and say, hey, you're supposed to use this warrior's outfit. We don't want to do that. What we want to do in the code is we create the class and say, hey, you have a skeletal mesh component. Here's the things that care what that mesh is. We're not going to tell you why or specifics. We're just going to say look for the skeletal mesh component. Look for this root bone. Keep it generic, right? Then in the blueprint, that's when the designer can come in and be like, you use warrior mesh. You use mage mesh. You use this one. And now we're going to go into those rigs. And we know that the bone that is coded is called item location. Just generic, right? right hand item location. So we create this socket on the warrior mesh and we put it right here and we orient it in the as a designer. So we grab it like this, and then the mage also has a right hand socket in the same position. Right. If you created a mask your code and then you have a master blueprint that is a child of your code, you can do that once on the skeletal rig. And then have it inherited to all of your child blueprints if you've set up your skeletal inheritance correctly. Now every single variant of hero you do automatically will have a bone in that position in the right hand in that spot. Like it's super modular when you get into the nitty-gritty like that, so that every blueprint, you don't have to set it up. You just set it up the one time. Now all of those sub-blueprints you can do interesting things with, like create custom offsets. Maybe your warrior class has just slightly bigger hands and you just need to offset it by 10 units and twist it a little bit, and then that changes how he holds things. That's
easy to do. All of your logic of where it is, why it's important is all handled in code and your parent classes, right? And your parent blueprints, all the child blueprints do is this is the object I'm holding. This is its location relative to me, and that's it. Once your interface is set up, it doesn't matter what you're holding. As long as that action of swinging or casting or whatever or like shooting the arrow does that interface of on hit do damage, explode, etc. I don't need to care what I'm hitting. My modular weapon system is modularly attacking objects in the world. That could be destructible objects, breakable props, it could be enemy types, doesn't matter. Right. Once that enemy dies, we use an event dispatcher to tell all the stuff that cares when that enemy died that it died. Incrementing counters, wave counters, like I said, achievements, triggering open doors, dropping loot, updating user interfaces. My subsystem that keeps track of how many enemies are alive so that I know the dungeon is complete. is also listening to that and it's managing everything so that when the dungeon's complete, all the textures are told, hey, swap to a pretty light version. So the dungeon is cleansed. There's like your four systems right there working modularly and you could swap out any of those components and all the code should still work. Changing your heroes, changing your items, changing your enemies, changing your dungeon layouts, all of that stuff will still work the same every single Where scope and bloat comes in is this is amazing. We're gonna have a swamp dungeon and a forest dungeon and a fire dungeon and an ash dungeon and a et cetera, et cetera, et cetera. And then before you know it, your art department is completely overwhelmed because your technical team is super like on point with the modularity, like it build a system.
Spencer: They're so modular with it, they're like, we could just keep putting in more and more.
James: Well, designers are usually where that happens. The designer's
Spencer: Tava.
James: like, the system accommodates this stuff, then we should do these things because players expect this. Because that's our role, right? A designer's job is about making the game fun, anticipating what players want, and curating what that experience feels like for a player. That's that's I I think the like the highest responsibility of a game designer. Where that becomes difficult. Is the designer wants to do things to achieve that experience, but at some point somebody's got to be there to be like, no, we're stopping at three dungeons because we have three artists and we don't want them working for the next five years. Our coders finished all the modular systems last month and they've been sitting here twiddling their thumbs waiting for stuff to work on. That's the role of the producer and the project manager mostly in most cases. is to manage that scope and be like, nope, nope, no, no, no. This is what coders are gonna work on. Designer, this is what you're gonna do. Artists, here's what you're gonna do. And we're gonna keep everything in balance. So everything develops in a nice flow. So nobody gets bottlenecked, nobody is stuck, artists aren't waiting on assets from coders, coders aren't waiting on assets from artists or designer feedback. Like everything flows. Sorry, small tangent, but I think it's important to address that.
Spencer: No. No, that's fine.
James: Like This is how the modularity can be a bad thing if you don't have somebody like strictly managing what are the deliverables. Because having that system is amazing because now you can go into extended content, content updates. You could do stuff like No Man's Sky and just infinitely pump out content like every couple months or you know, however their cadence is. You could do DLC, you could do live service games, and no, everything is gonna work every time. And you can create custom rules on a per actor or per object basis, right? I want an enemy type that clones itself. That's cool. Does it have to be in the base game? No. Is it possible to be in the base game? Yes. It just uses all the same rules as everything else. It just has its own unique code to be like, hey, make another one of me. That's super easy. But like managing that with the subsystem and all that stuff, that's where the modularity is really powerful. But being able to put a pin in that and be like, that's next, that's in the summer. That's quarter release, quarter one, quarter two, right? That's where it becomes really powerful. yeah, so like that's the distinction between code and blueprints, visual scripting. That's how you should separate them. and then that also like we just talked about like the bloat and the memory management kind of we sort of touched on. but your hard references, just to touch on those again, right, they're bound directly to objects. When the caller is loaded, the receiver is forcibly loaded. We talked about that, which is why it's important to make sure whatever you're casting to is already loaded. We don't want to have too much. Where you kind of get around that is by using soft references. That's just a string wrapper containing the file path to an asset. So a soft reference, it doesn't load the actor the same way until you ask it to. So this is where we can get around and do some like higher end optimization with the code, where if we must cast to this door, there's this the only way this is gonna work out. You could do a soft reference cast. So the code will still function. It'll say, I know what this object is. I've compiled the code as if it is true so that the game will load and everything will function. But I'm not gonna run the code because you didn't tell me, hey, load this asset. When we go to interact with that door, we could tell it load the soft reference on this door and then run the code. Now we're gonna load that door the moment we need it, and so that keeps your map your memory. relatively free up
until you need that object. So that's good for situations where you must cast and you can't figure out how to use any of the other communication methods, but you also want to make it lightweight. What's difficult
Spencer: Okay.
James: there is making sure that you load it, right? This is where people get it kind of mixed up is once you set the soft reference, you still have to load it before the reference is needed. Which is why I I I think that having on an interface to tell it to load the soft object if it has one is a a really easy fix for that to catch whenever that is needed, basically. So if you're ever designing a game and you're like my stuff is just like way too involved, you can break it up with soft references. Now, earlier I mentioned how event dispatchers broadcast, right? But part of broadcasting is that the subscriber needs to cast to whoever's broadcasting, the publisher, to listen for that event, right? It's a hard reference. You can make that a soft reference as a double layer of optimization there. So your subsystem doesn't necessarily need to know when, like it doesn't need to load up that door that it's supposed to listen to. Because if you think about it. If all the objects in that corruption example are the subsystem is listening for, it's creating a hard reference for all those objects. Now the subsystem is permanent, so and theoretically all those objects should be existing in the level if everything is run right. But they are still all loaded. Even if that door is way off screen, it's loaded in memory. It doesn't exist in code, which is why you get errors, right? It doesn't exist, it's not valid, but it is still in memory. So To manage that, you make a soft reference inside your subsystem. Now, your subsystem doesn't care whether or not the door is there or if it's needed. But when that door runs its on begin play or is active or initiate whatever function you're running in whatever engine to basically turn on that asset to make it exist, you can tell it to run an initialization function where it tells the subsystem. Because remember, the subsystem always there. It's okay to cast to it. You cast to the subsystem and tell it, hey, I exist now, load the soft reference and do the binding. So now the subsystem says, okay, I'm gonna go look at you now that I know you exist, and I'm gonna load up the binding so that when you are destroyed or whatever interaction we have, I know to listen for that. So that's how you use soft references to basically lessen the load on your on your direct casting. Cause if you're you and and that's where it's important, using a direct a soft reference for something in your world that always exists, there's no reason to do that as a soft object, but it would be in the case of the subsystem, because the subsystem is keeping eyes, right? It's listening for everything. So you would use a sub a soft reference there. And so that's how you can use those two systems to kind of do a little little tricky communication to say it's important for the subsystem to care about all the traps. We don't want it to load all the traps at once because that'd be a nightmare. So it's all soft references. But when a trap loads in, because we opened a door and it's procedurally generated for the first time, we're going to tell that trap to tell the subsystem, hey, I exist now. And then the subsystem will register it in real time. And because it's loaded, it does exist now. It's not something that will be loaded eventually. It exists now. And so the delegate works fine. There is a smaller element there where you can unregister stuff, which I think that's way more like very experienced, but anything that you register with an event dispatch, you sort should also unregister. So when the trap is triggered and we don't care about it anymore, tell the subsystem to forget about it. You say deregister it, unbind it, because otherwise the subsystem will just continuously monitor for it. Now that's like bites.
Spencer: You've got a system monitoring a
James: It's bites.
Spencer: thousand old traps that are all dead.
James: Yeah. Right. And so where something like this becomes very relevant is in those bullet hell style games, vampire survivor games. You don't want your scoring subsystem, your wave subsystem to still be listening to like the you said, the thousands of enemies you've already slain. Because after a while, those little bites of data that it's listening for for every single one is going to start stacking up. And you're gonna have a bit of a memory hog and you're not gonna know why. Cause it's not wrong. It's not gonna get flagged. The only way to know that would be to play the game for like 10, 15 minutes with a profiler running, which is a lot for a lot of systems, right? For your casual developer, I say. It's really hard to track that down and narrow it down and figure out, yeah, look at this subsystem. It it it's it has tons of memory. Why is it ha why does it have tons of memory? Well, it's gonna be really hard even then to diagnose it because you're like, well, there's 400 enemies on screen. That makes sense. So why is this still so bad? You see where like it's really hard in that scenario.
Spencer: Mm-hmm.
James: So that's why there is the option to unregister, to unbind in Unreal, like those events is so that once that event is triggered on that object, we don't care about that object anymore. We can tell that object on death to do the exact same thing. Hey, subsystem, I died. Forget about me. And then it disappears and the subsystem says, okay, because there's an internal ledger for anything that is subscribed to anything else in the game. Anytime something is there listening, it will forever listen. And so you can imagine that at scale, right, across a whole dungeon, every single enemy is listening for different kinds of dispatches, different subsystems listening for different different dispatches. After a while, that's a lot of memory that stacks up.
So it's like another way to manage that memory. complicated, but but this is pretty advanced. And there's lots of different ways of tweaking with this, different techniques that we're we're not gonna go into, but things like spawn pools, right? You just always permanently load 30 versions of something and it never really dies or lives. It just exists at zero zero zero under the map forever. And then whenever we need it What we actually do is we turn it on and teleport it to a position. It does its logic, and whenever it hits or despawns or whatever, it doesn't die. It just turns off, goes invisible, and teleports back to zero, zero and goes down to a bottom of an array so that it's ready for the next iteration. That's how bullet bullet hells manage all the craziness craziness that's on screen. None of that stuff is generated real time. Well, most of it is not generated real time. It's already loaded. It's just not doing anything. Because the act of creating and uncreating, destroying actors is very expensive on your memory as well. So you that's another technique to manage all this kind of information. Yeah.
Spencer: That's really clever.
James: And and you can get into some really interesting code communication with your delegates by registering and unregistering on begin play. And on actor destroyed in Unreal, where you could do stuff like procedural systems that automatically what's a good example? I did a workshop a while ago and somebody took that that procedural registering and under registering to create a quiz system that dynamically updated every round for like different answers according to how many like questions you wanted according to a question data asset he made. So you you want a true this next question is a true and false. So it spawned two options. One was true, one was false. And then the next one is a is a multiple choice. So it spawns four. And all four at runtime automatically register and deregister with you know the code that manages the correct act answer. And so the way he did it was through pads. So as a character, you just run over, you get the question, and then multiplayer you run over like fall guys style. And jump on the pad. And then the delegate fires to figure out on creation which one is real, which one's not. And then when the answer queue fires off and says, this is the right answer, they all listen. And the one that's correct goes green, and the other ones are red, and everybody dies except for the people who are on the right answer. And so that's all dynamic run running at real time. All you had to do was just set up a data asset for like here's the question. Here's out of A, B, C, D, true or false, you just flag which ones are relevant to that question. And then you list out what those answers are in in in your data asset. option A is this, option B is this, option C is this, and then here's the correct answer. And then you just you can create an unlimited number of questions like that. And your spawning mechanics, your victory, your winning, losing, all that kind of stuff. Purely mod modular. Once that's done, your limit is just how many you want to make. Which is just typing in chat and flagging those options. it's a very clever system way of leveraging that on spawn, like dynamic registering and and for for the delegates, I mean, right? It's very it was very neat, it's very clever, it was very cool. but you could do that kind of stuff with all kinds of stuff, like a procedural dungeon system. You want it to pick any random number of rooms. And you just want to say, hey, the boss door has a random number of one to four keys every time we generate this level. And we're going to randomly pick rooms to spawn a key. And we want them all to sync up correctly with the door. And like all of that you can code using these communication methods we've talked about so that it runs correctly every single time. And then once that's done, your content work is like, what does the door look like? What is the animation on the door? What do the switches look like? Do we want to have different kinds of switches? Maybe one's a button, like a brick that we gotta find, or a book in a bookshelf. Like it doesn't matter. But now the work is not on the system. Now the work is on the content that fits in the system.
Spencer: That's cool.
James: So I was I got on a ramble there, but yeah.
Spencer: Well, where do you want to go next with this?
James: I think right now, Pretty much at the end of that. But if you're still listening, right, what I would challenge you to do, if you're in Unreal or whatever the equivalent is, is open up your your project that you're working on and select like your main character, right? Or whatever a core component in your game is, and specifically use the size map tool in Unreal. And what that's gonna do is it's gonna load up your character blueprint and it's gonna show you everything that is loaded. When you load up that character blueprint. And if you see a bunch of stuff in there that shouldn't be in there, like like non-persistent things, really you're looking for things that are not UI widgets or you know, your controller or subsystem related, maybe everything else that loads up, your weapon assets, your enemy classes, all your generic stuff like that in the world that you're Player characters interacting with all that stuff should not be there. And I think you'll be shocked. Like if you've never done this before and you've been relying really heavily on direct casting, you're gonna open up some of your assets and you're gonna see like 30, 40. I think the worst one I've ever seen is over 217. And that wasn't even all of it. It just stopped there. It just said 217 plus in Unreal. That's how many, that's how many different things were loaded.
Spencer: That's crazy.
James: Because I did size map on one actor and it was not the player character actor either. It was an actor that was in the world that that particular developer had used like a manager, right? To manage everything else, which which is not bad, but they just did not know how subsystems worked or that they were even a thing, right? And then when once we walked through it and it was like, and then he transferred the whole system over and it was great. Like his game, his game like shrunk. to a third of of the size and it ran so much smoother. But he just didn't have the context, right? But that's how bad it could get is when you don't know how the communication affects things and it gets out of hand. Now think like an additional year of development, that 217 plus things and something breaks. How do you diagnose that? How do you use the insights tool to profile stuff to figure out where's your memory leak? You have no idea because everything is loading. So where's the culprit? And simply just sorting by which one has the biggest RAM allocation or memory allocation doesn't always help you because your asset that's lo loading all the things in cascading fashion, each subsequent, load or reference is gonna have a bloated blueprint because it's loading everything else after it. So yeah, that that that's really what makes profiling and using the insights tool and just trying to, you know, even Task Manager. Right, in the most basic form, a lot of people will load up Task Manager and be like, Look at my GPU is fine. And it's like, Yes, but when it's not fine, how do you use that to figure out why it's not working right? And yeah. So it it saves you a lot of headache in the long run understanding this stuff early. So that's my challenge. Is load up something in your project that's in a lot of a lot of your levels or your game systems and see just how big your size map is.
Spencer: Well, James, is there anything else you'd like to to mention about this then before we wrap up the episode?
James: Normally if you're co if you're if you're making some cool stuff, you know where I'm gonna tell you to go, so you can come share it and then we could talk about it. But other than that, nope.
Spencer: is it the Indie Innovators Discord and the links in the description?
James: I was gonna say LinkedIn, but no, that's that's much better.
Spencer: Yeah, well, LinkedIn too. You can always do that.
James: No, India Innovators Discord. Please come on in, stop by.