Accessing custom relationship trait array at runtime

Announcements, support questions, and discussion for Love/Hate.
Post Reply
joeykid6
Posts: 17
Joined: Thu Feb 07, 2019 1:57 pm

Accessing custom relationship trait array at runtime

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

Re: Accessing custom relationship trait array at runtime

Post 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);
}
joeykid6
Posts: 17
Joined: Thu Feb 07, 2019 1:57 pm

Re: Accessing custom relationship trait array at runtime

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

Re: Accessing custom relationship trait array at runtime

Post by Tony Li »

Thanks! Always happy to help.
Post Reply