Forum rules - please read before posting.

How to spawn an NPC run-time

There is a similar question already, but it went in a different direction than the question I am having.

I wonder if I can spawn an NPC run-time, and if so, how to assign a location and rotation.

I'll have NPCs "walk between" scenes so will have to spawn and despawn them.

Or would it be better to have all NPCs who can be in the scene in a "box" where the camera won't go and teleport them? And if so, can I turn following nav-mesh on and off, as they will be off the nav-mesh while in their "box".

Comments

  • Would this be for a 2D or 3D game?

    Both are valid options - you can keep the NPCs hidden off-screen, or spawn in their prefabs at runtime with the Object: Add or remove Actions.

    However, it'd be difficult to keep track of what NPCs are visible, and control them after spawning, this way.

    It depends on the complexity of what you're going for, but the recommended way of handling such situations is to make use of AC's Player-switching system - where each NPC is actually a Player prefab listed in the Settings Manager.

    When this is done, AC will keep track of each listed Player's scene and position - even if they are not currently the "active" Player. An "inactive" Player like this will be treated like any other NPC - only you can use the Player: Teleport inactive Action to move them between scenes, and check Is Player? in character-related Actions to select them from a drop-down.

    More on this topic can be found in the Manual's "Player switching" chapter. If you want to pursue it, you can convert NPCs to Players via their component's Cog menu.

  • It's a 2D game.
    Is there a limit to how many "player character"s there can feasibly be?
    I intend to create quite a well populated game.

    I had not considered that though, so will have a read through the manual for it!

  • Is there a limit to how many "player character"s there can feasibly be?

    There's no hard limit, though you may want to reference them via Addressables if you have many, as this'll avoid having your Settings Manager directly referencing them (and thus all being loaded upon startup). That's something that can be done at a later stage, however.

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.