Creating FactionManager and FactionMember programmatically
Posted: Wed Sep 05, 2018 8:54 pm
Hello,
My first question is how can I create a new FactionManager GameObject from a script? I saw on an older thread (viewtopic.php?f=5&t=724) that you recommended doing something like this:
However when I do that, the Awake method for FactionManager logs a debug error since the faction database is not assigned yet. Is there a way to do this? My project is going to have several managers and I want to create them from the main GameManager so that I don't have to add a bunch of things to every scene.
My second question is what's the best way to do the same thing for FactionMembers? My project has a lot of procedural characters and I was hoping to just be able to create new factions for them and add them to the database at runtime.
From that same thread I saw an example of creating them: (although I think I'll be instantiating a prefab with the base character components and then either adding a FactionMember component or updating the existing component on the prefab)
and I just want to make sure that are not any hidden "gotchas" that I'm going to run into doing things this way.
Thanks!
My first question is how can I create a new FactionManager GameObject from a script? I saw on an older thread (viewtopic.php?f=5&t=724) that you recommended doing something like this:
Code: Select all
// Create FactionManager:
var factionManager = new GameObject("LoveHate").AddComponent<FactionManager>();
factionManager.factionDatabase = myDatabase;
My second question is what's the best way to do the same thing for FactionMembers? My project has a lot of procedural characters and I was hoping to just be able to create new factions for them and add them to the database at runtime.
From that same thread I saw an example of creating them: (although I think I'll be instantiating a prefab with the base character components and then either adding a FactionMember component or updating the existing component on the prefab)
Code: Select all
foreach (var character in myCharacters)
{
var characterGO = new GameObject(character.factionName);
characterGO.transform.SetParent(factionManager.transform);
character.factionMember = characterGO.AddComponent<FactionMember>();
character.factionMember.factionID = factionManager.GetFactionID(character.factionName);
// Add other components:
characterGO.AddComponent<StabilizePAD>();
characterGO.AddComponent<EmotionalState>(); //etc.
}
Thanks!