Hi all,
I've been struggling to find the best way to approach this in AC for a while now. I'm currently working on a new project in my free time, and I'd like to pose a question as I've not been able to find any existing threads or discussions on the subject.
What's the best way to clone an NPC prefab in a scene? Say, for example, I wanted to have 3 NPCs of the same type, but I only wanted to use 1 animation controller, and I also used "Link Variable to Animator." Is there a way to handle something like this, or do I need to create individual controllers for each?
I'll have 3 specific instances in a turn-based battle system I want to implement (attack, die, scan), which I'd like to run per prefab instance. The problem is, if one plays, they all play at the same time. Creating 3–4 controllers for each clone and just resetting them and respawning them wouldn't be a problem—I'd just like to know if there's a correct way, or if I'm taking the scenic route again.
As always, thanks in advance, and I wish you all a great rest of your weekend!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
You can have multiple objects in the scene that use the same Animator, but if they're linked to the same variables then they'll all react the same way. You can link to Component variables, however, so that each character has unique variable(s).
I need more context on the issue, however. Can you elaborate on the underlying situation?
Hi Chris,
Thank you for taking the time to reply. It's not an issue, really.
I'm trying to figure out the best way to achieve the following: I'd like to have multiple instances of the same NPC (sharing one controller per enemy type) at runtime. All NPC types will follow the same naming convention, including custom animations, to automate things as much as possible. I'll use parameters as well.
The thing is, for actions like "attack," "death," and another custom feature, "scan," I need to use Link Variable to Animator to trigger them directly and easily, without adding a lot of variable checks, etc. The problem is, if all the enemies have the 3 variables I mentioned linked, triggering one of them will cause all the enemies to play the animation at the same time.
My question is: can I use variable presets or some other trick to avoid this, or do I need to figure out a different design approach? For example, during a turn-based battle instance, could I show only one enemy and obscure the others, reset the variable, and then spawn the next one?
As always, thank you in advance.
It should be just as above: if you rely on component Variables, instead of Global, such that each NPC uses their own set of variables, then they should remain independent and unaffect one another.
By component variables: I'm referring to the Variables component you can attach to a GameObject. This is compatible with the "Link Variable to Animator" component.