Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question What's the best way to manage lots of different characters that have complex setup (AI/IK/ragdoll)?

Discussion in 'Editor & General Support' started by darthdeus, Feb 24, 2024.

  1. darthdeus

    darthdeus

    Joined:
    Oct 13, 2013
    Posts:
    80
    Currently my NPCs have:

    - Pathfinding/AI components
    - Ragdoll via Puppetmaster, this has a non-trivial setup
    - IK with FinalIK, both for aiming and limbs, which includes adding extra transforms
    - Animations
    - Utility components binding things together (e.g. tagging limbs in the ragdoll hierarchy)
    - Mesh separation with Gore Simulator (allows cutting off limbs), again non-trivial setup per mesh
    - Gun, which is attached somewhere in the hierarchy

    I imagine most games that have a bunch of humanoid enemies that aren't as unique do some kind of sharing.

    My game is in a "current time non-sci-fi" setting, which means just various human models. I'm not creating all of them from scratch and for the type of game I'm making I'd rather have "quantity over quality", which means some models might have differently named/split up meshes, although they all conform to the humanoid avatar.

    I'm not exactly sure how to best structure this. Initially I just made a custom editor window (with Odin) where I can just select a character mesh, press a button, and it'd run through Puppetmaster/FinalIK and attach all the components and do everything I need, and then I'd create a prefab out of this.

    The problem is as I'm adding a few more things this doesn't really scale very well, and gets annoying to re-create the prefabs when things change.

    On the other hand, I'm really not sure how to utilize prefab variants for this, as Puppetmaster has a relatively specific setup that unpacks prefabs. Similarly, Gore Simulator also requires some mesh processing where it'll combine all the sub-meshes of a character first.

    One thing I thought about is to treat the character as a "lower level" node, and instead attach all of my pathfinding/AI stuff to a sibling/parent node, to at least allow some kind of sharing of logic, but I'm a little afraid of what's the best way to handle this.

    What I imagine as the most flexible/optimal solution is something like

    - character - just an empty transform that combines the two
    - "AI prefab": pathfinding/local avoidance - general purpose prefab
    - "body prefab": ragdoll with IK & animations - one prefab per character

    but I'm really curious about how people solve this. I imagine there could be one character prefab variant per character that just embeds the correct body.