[HOWTO] How To: Create Factions At Runtime

Announcements, support questions, and discussion for Love/Hate.
Post Reply
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Create Factions At Runtime

Post by Tony Li »

This post explains how to create factions in code at runtime. You can also create factions in visual scripting systems such as PlayMaker and Game Creator.

To add a new faction, call FactionDatabase.CreateNewFaction. You can access the faction database using FactionManager.instance:

Code: Select all

FactionManager.instance.factionDatabase.CreateNewFaction(factionName, factionDescription);
To set a faction's parents, use FactionManager.AddFactionParent:

Code: Select all

FactionManager.instance.AddFactionParent(factionID, parentID);
(To get a faction ID from a faction name, use FactionManager.GetFactionID.)

To add a new faction member, just add the component and set its faction ID:

Code: Select all

var member = myGameObject.AddComponent<FactionManager>();
member.factionID = FactionManager.instance.GetFactionID("Some Faction");
The FactionMember component's Start method registers the faction member's faction ID with the faction manager.

If you want to switch a faction member's faction after its Start method has run, use FactionMember.SwitchFaction:

Code: Select all

factionMember.SwitchFaction(newFactionID);
See the FactionManager, FactionDatabase, and Faction class references for information on how to add relationships, set personality trait values, and more.

See also: Complete API Reference.
Post Reply