Page 1 of 1

Accessing custom relationship trait array at runtime

Posted: Tue Oct 15, 2019 2:10 pm
by joeykid6
Hi Tony,

I can't seem to find anything in the API for accessing the relationship trait array at runtime. I have custom relationship traits beyond affinity. The closest thing I can find is:
PixelCrushers.LoveHate.Relationship.traits

However, I can't see a clear way to access this from the FactionManager instance and live FactionDatabase at runtime.

I need the whole array so I can iterate over it.

Let me know what you think, thanks!

- Joe

Re: Accessing custom relationship trait array at runtime

Posted: Tue Oct 15, 2019 4:46 pm
by Tony Li
Hi Joe,

Iterate through the faction database's relationshipTraitDefinitions array.

To show all relationship types:

Code: Select all

var database = FactionManager.instance.factionDatabase;
for (int i = 0; i < database.relationshipTraitDefinitions.Length; i++)
{
    Debug.Log("ID " + i + ": " + database.relationshipTraitDefinitions[i].name");
}
A relationship trait's ID is its index in this array. (Love/Hate was designed to support simulations of thousands of simultaneous units, so the underlying structures like this run pretty close to the metal.)

To show Jack's relationship values to Jill:

Code: Select all

for (int i = 0; i < database.relationshipTraitDefinitions.Length; i++)
{
    int relationshipTraitID = i;
    TraitDefinition relationshipTraitDefinition = database.relationshipTraitDefinitions[i];
    float relationshipValue = database.GetRelationshipTrait(jackFactionID, jillFactionID, relationshipTraitID);
    Debug.Log("Jack --> Jill " + relationshipTraitDefinition.name + ": " + relationshipValue);
}

Re: Accessing custom relationship trait array at runtime

Posted: Tue Oct 15, 2019 7:03 pm
by joeykid6
Wonderful, thank you!

It seems silly in retrospect, but I saw that and thought it would only give me the trait descriptions. Oh well, I should've known you had it covered; your code is always so meticulous.

Re: Accessing custom relationship trait array at runtime

Posted: Tue Oct 15, 2019 7:31 pm
by Tony Li
Thanks! Always happy to help.