[HOWTO] How To: Create Factions At Runtime
Posted: Sat Aug 31, 2019 8:48 am
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:
To set a faction's parents, use FactionManager.AddFactionParent:
(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:
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:
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.
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);
Code: Select all
FactionManager.instance.AddFactionParent(factionID, parentID);
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");
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 also: Complete API Reference.