Forum rules - please read before posting.

Crowds

One of the scenes in my game is going to have many people wandering around the environment. Is AC "equipped" to deal with this, or shall I use alternative code for crowd behaviour? I have seen an asset on the asset store that does just that, but I'm wondering if there is any disadvantage to using AC's NPCs rather than bringing another API into the equation. It is only one scene in the entire game that will contain all these crowds of people.

Comments

  • edited September 2016
    Umm... I'm not sure how AC characters are threated. Though, I would use object pooling for such an scenario, to make sure things don't get too heavy (specially if the passersby are going to be many). In case you're not familiar with object pooling it just means creating a bunch of objects from the get go, but keeping them disabled until they're needed (you also need to keep a reference for the whole pool, because unity has a hard time finding disabled objects). That way you can pull one object from the pool when you need it in the world and when you are done instead of destroying it, you just return it to the pool to wait until it's needed again. That saves memory and unwanted lag (destroying objects too often causes slowdowns).

    But, all that would depend on how many passersby you are expecting. I would have them disappear once they get out of the screen though. Leaving then moving around while they're not visible would definitively be a waste of processing. If you are not a programmer I think there's a few pooling systems in the asset store (I think there are a few code examples in the unity forums and unity answers if you don't have the money).

    For the moving, I guess you could try having a custom script in the characters to run an actionlist OnEnable. So that they start moving automatically without a hassle, following some paths or markers (if you want to see an example of how to run an actionlist from code you can take a look at my custom triggers in the wikia). Or you could always get something more custom from the asset store. Mind you this are ideas, there's probably other ways to have the character's move, but you'll have to think a little longer.
  • Would this be in 2D or 3D?  You may have to look into playing with your NavMesh's accuracy if it's in 2D.

    2D NavMeshes have a number of controls for optimising performance at the cost of accuracy, as well as a "Character evasion" feature which you may have to disable if you have many NPCs moving around at the same time.
  • @Alverik: Thanks for the detailed response, a few approaches to consider.

    @ChrisIceBox: Sorry I forgot to mention it is 3D.

  • About five or six months ago (back when I was still best friends with Unity) I was testing out Opsive's Behavior Designer system to deal with groups of generic NPCs (one or two dozen at a time) in a city scene in AC with quite promising results.

    As I've recently been spotted on the Opsive forum, I can no longer keep it a secret: me and Unity might be in the process of making up, so I'll try and dig out the code from my archives and see if it still makes sense.
  • Hey, great! I'd love to see that code :) I'm also planning to have some scenes with crowds, if it means not having to start from scratch that would be awesome! :)
  • edited September 2016
    Couldn't immediately locate the original scene I was working on, so here's a fresh one quickly thrown together to show Behavior Designer in AC. The Ethans are not actual NPCs in this version, just wandering hotspots, and their behavior is about as primitive as it gets, but I hope it gives some sort of idea of what's possible with this setup.

  • @Snebjorn: Great Snebjorn! I actually bought Behavior Designer a long time ago because I knew Opsive would have an integration with their Third Person Controller, which I am also using. So you just parented hotspots to the npc models and gave them a wander task?

    I wondered what you were up to on the forums there.

    ;)
  • edited September 2016
    Haha ... who knows?  :)

    But yeah, it's just the standard Ethan model with a hotspot and a BD wander task. Would be quite easy to extend into something more convincing. BD comes with very minimal AC integration (just var sync if I remember correctly), but back on the original project I was working on better handling of AC chars, specifically for the purpose of having lots of filler NPCs for street scenes.

    Will try and find the code and put it on the AC wiki - it's just that I've been working mostly on audio and music assets lately, thus eating up disk space like crazy, so most of the old stuff is now filed away on external drives.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.