Page 1 of 1

Dynamically assigning faction

Posted: Thu Dec 03, 2015 6:49 pm
by iDisagree
Hey -

For my game I need the ability to assign a faction dynamically, in code, when an NPC is created. Is this something that's possible or do I have to do it through the Unity UI? If it's possible where can I find the documentation for it?

Thanks!

Re: Dynamically assigning faction

Posted: Thu Dec 03, 2015 7:53 pm
by Tony Li
Hi,

In code, use FactionMember.SwitchFaction(factionID).

If you need to create an entirely new faction, use FactionDatabase.CreateNewFaction(factionName, description).

There are also equivalent PlayMaker actions in the Third Party Support/PlayMaker Support package.

Re: Dynamically assigning faction

Posted: Fri Dec 04, 2015 11:20 am
by iDisagree
Thanks Tony!

I somehow missed that in the documentation :) Another Q - let's say I want to create a faction dynamically.. Well, I do want to because each "user" should have their own faction, but "users" are dynamically created at load time (and other times, as well).

Anyways, is there a way to set the Personality Traits for the newly created faction?

Re: Dynamically assigning faction

Posted: Fri Dec 04, 2015 11:34 am
by Tony Li
Hi,

You'll probably want to inherit values from the faction's parents first. To do this, use FactionDatabase.AddFactionParent(factionID, parentID) to add parents. Then use FactionDatabase.InheritTraitsFromParents(...) to inherit values. There are a few overloaded variations of InheritTraitsFromParents that you can choose from.

If you have a reference to the faction (e.g., FactionDatabase.GetFaction(factionID)), you can set individual traits through the faction's traits array. The elements in the array are the traits' float values. The array corresponds to the faction database's personalityTraitDefinitions array. You can use FactionDatabase.GetPersonalityTraitID(traitName) to get the array index for a specific trait.

Re: Dynamically assigning faction

Posted: Fri Dec 04, 2015 11:54 am
by iDisagree
Awesome. Best support ever :)

I saw the traits array, was unsure of how to get the right Trait id but I was looking on FactionMember instead of FactionDatabase :) A theoretical question (maybe I should have made these separate threads?!) - Is there any sort of max number of factions you envision? Would a few hundred different factions, each with just one member, be okay?

Re: Dynamically assigning faction

Posted: Fri Dec 04, 2015 12:23 pm
by Tony Li
Hi,

Thanks! :-)

A few hundred factions will be fine. I stress-tested with 10,000 factions to evaluate whether to add an optimization that would have made the code more complicated. Since 10,000 factions ran fine, I opted for simpler, clearer code instead.