Back to search
Star Citizen Live ·
Published on this date.2021-05-28
· 4 Q&As

Star Citizen Live Gamedev: Building NPC Behaviors

Developers explain how NPC behaviors work as data-driven "brains" that designers can build without code. They cover usables, why broken hierarchies and missing tags are hard to debug, tag priority in Mannequin animation, and why NPCs stand on chairs.

Transmission log

Full answers

What is an NPC behavior, and what are we doing [today]?

TL;DRAn NPC behavior is the brain of an NPC, built as data-driven, modular activities such as a job like engineering, with decision logic and environment understanding, demonstrated through an engineer behavior built from scratch.

Basically, I think all of us here work both on... some of us, as a programmer, work on some of the systems we define, we design and we build, implement. Some others, as the designers, are mostly working with the systems we build and they help us building. So the behaviors are mostly the brain of the NPCs, right? So the way we split the things is we try to build, first of all, as much as possible... it needs to be data-driven to scale up, right? This game is so huge. We need to just allow designers and content creators to create content that we use automatically, right? To patch the game and expand the game. And one of the things we want to show today is something that me and Dan have been working on for a while. And I think we also showed some sneak peeks, mostly during the monthly reports, but it's the engineer behavior, as an example of how we build a behavior from basically scratch, right? So how we define mostly what we want an activity to do, because we talk about behaviors in terms of activities. Usually an activity is kind of a generic representation of a job, right? It could be the engineering job. It could be the pilot security that Jacob has worked on, or the tourists that Hayden has been working on. Something that the NPC can do. I'm sure a lot of people that are watching here saw Tony's video that was out this week, with all these things with the population manager and the virtual NPCs. With this really cool population manager we can basically spawn them in the right context, and their context is the activity of what they are trying to do and the environment in which they are in. So basically that is what behavior is. And to achieve that, let's say an engineer, there are a lot of pieces that we have to take care of, like building the environment or making sure that the NPCs understand the environment as well. And then there is the actual decision logic, decision flow. And what that means is that we try to abstract our thought process flow. It's like, oh, I want to find something that is broken. I want to repair something that is broken. And then how that basically constructs the actual action that they need to perform. It tries to be as generic as possible, as modular as possible. And this is what we'll see today.

Star Citizen Live›Gamedev: Building NPC Behaviors·
Published on this date.28 May 2021

How often is a hierarchy broken? Because you have to create 20 different links in order to make these things, and if one of the 20 links is broken, the whole thing doesn't work.

TL;DRThe team says broken hierarchies are common and hard to debug, since a single missing tag can cost half a day, so they add debug drawing and debug by removing parts one at a time.

Yes. And the problem is often... I'm sure Dan or Hayden or Idris can say more. It's so easy to even get lost sometimes on why things don't work. And I think we are basically constantly trying to say, okay, this is the problem, so let's try to add some extra debug draw to try to track it easier next time. And we try to do that, or, oh, the message is not really clear. Right, Dan?

IdrisAI team

It could be the most simple thing ever. It could just be you're missing a left tag, you're missing a right tag, and then you'd spend half a day debugging it. And you're like, oh, it was just that. You missed this one little field. But yeah, there's a lot of information going into these usables.

Dan BakerGame Designer

You can spend quite a bit of time just breaking a single entity down to its core parts, just saying, okay, well, this is okay. So you take that out and then you put a different thing in. And it's a bit like if you're building a PC and you just swap out different components just to see which one's the broken bit.

Yes, absolutely. That is usually a very good, easy way for debugging stuff. You start to remove and say, is this the one that broke it? Or just do a little step at a time.

Star Citizen Live›Gamedev: Building NPC Behaviors·
Published on this date.28 May 2021

Do tags have a priority? Are some tags more important than other tags? If an NPC recognizes a conflicting tag, does it prioritize one or the other, or does it just jump up on the chair and not know what to do?

Dan BakerGame Designer

I think that depends on the logic more than anything. I mean, all tags are created equal. It's just how you use them. Whereas mannequin tags, they do have a priority. So say it was something more important, like I'm being shot. That's probably going to be a higher priority animation tag than just a standard idle, for example.

JacobJunior AI Programmer

Also, you have hierarchy in tags, as far as I know. For instance, you can have an entity with an outfit tag. You can have an entity with a very specific outfit as well. So you can work with the hierarchy of tags as well in that regard, if you want to make any specific behavior based on the hierarchy structure of the tags.

Dan BakerGame Designer

Yeah, it's so fundamental, you can use them in pretty much any way you like. That's one of the best things about them.

Star Citizen Live›Gamedev: Building NPC Behaviors·
Published on this date.28 May 2021
NPCs & AI

Why do NPCs love standing on chairs so much?

TL;DRNPCs standing on chairs is one visible symptom of many different bugs, mostly streaming-related, which the team keeps fixing and plans to schedule dedicated time for, with the population manager expected to make it a non-problem.

Dan BakerGame Designer

I think Fran's answered that a few times already, haven't you? It's one of those things. I mean, I've answered it when I've been doing Star Citizen streams as well. It's one of those kinds of bugs that has the exact same visual output, but it has lots of things that can cause it. So you fix it one way and then the next week you've got the exact same visual output, but it's a completely different bug. It's just one of those.

JacobJunior AI Programmer

There's so many things going into the usable code. It's really a jungle sometimes to figure out what exactly is causing this bug.

IdrisAI team

Yeah, definitely. It could be a missing animation. It could be the animation names changed. It could be the setup changed slightly by accident in the parent above the variant. So it could be absolutely anything.

Dan BakerGame Designer

I remember one reason. It was caused by people leaving the area, then the NPCs that were still sitting in the seats basically got turned off. And then when a player came back, they were turned back on, but the game didn't put them sitting correctly in the seat anymore. So they were just standing on it instead.

There are tons of problems basically that are causing that, and they're mostly coming from the streaming right now. I'm the first one that hates that bug. The problem is that the AI is at the end of the chain. So every time something gets improved, we get these side effects that all look like the same bug. But for standing on the chair, this is what we are trying right now. We will dedicate some time to make a proper plan. I'm scheduling some time, because I'm a bit tired of seeing it. Of course, eventually, I really want to have a proper animation of a guy standing on the chair just on purpose, and it would be like, gotcha, a one in 1,000 NPC. One in 1,000, it will happen, and he does it on purpose. Yes, we need to do it. But it's basically a lot. Sometimes, for example, when something streams out, we don't know that it will eventually come back. We can't right now guarantee it, because we don't have the proper persistence of that stuff yet. So we either reserve that object for somebody that might never come back, or it might come back with a different ID. And sometimes it's like, this was yours, but now you can't use it because it's reserved for somebody that is never going to come back. So we are not doing it. And then, of course, sometimes what happens is another NPC actually sits there before. And this is why you sometimes see two NPCs, one next to each other. The streaming takes too long, and then the guy's already there. But there are also lots of fallbacks in place already, and whenever we find them, we basically add them and then we try to recover from some of the situations right now as well. So there are a lot of little pieces, because with the population manager, of course, this is meant to be different, right? When NPCs go away, those will be repopulated by the population manager. So this is why, in a way, this is not really a problem that will exist in the future, right? Because with our plan it's already a non-problem in a way, the fact that the guys just come back because the streaming kicks in, right? But then there's of course the stuff that there might be some bugs sometimes with the LOD update. We try to be efficient in updating stuff that is not visible, and maybe that one fails to attach, and we are searching for some of this stuff. So, as Dan said, it's the same visual problem with several bugs that we are constantly fixing, and some new optimizations and things might still bring it back.

Star Citizen Live›Gamedev: Building NPC Behaviors·
Published on this date.28 May 2021