Dynamically assigning faction

Announcements, support questions, and discussion for Love/Hate.
Post Reply
iDisagree
Posts: 8
Joined: Thu Dec 03, 2015 6:45 pm

Dynamically assigning faction

Post 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!
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dynamically assigning faction

Post 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.
iDisagree
Posts: 8
Joined: Thu Dec 03, 2015 6:45 pm

Re: Dynamically assigning faction

Post 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?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dynamically assigning faction

Post 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.
iDisagree
Posts: 8
Joined: Thu Dec 03, 2015 6:45 pm

Re: Dynamically assigning faction

Post 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?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Dynamically assigning faction

Post 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.
Post Reply