Setting Personal Affinity - but database not updated

Announcements, support questions, and discussion for Love/Hate.
Post Reply
haavard
Posts: 6
Joined: Thu Sep 29, 2022 12:49 am

Setting Personal Affinity - but database not updated

Post by haavard »

Hi,

In script I'm using "factionMember.SetPersonalAffinity(factionID, 0f)", to set a relationship with a NPC that the player meets in the game. But when I use factionMember.faction.relationships.Count to loop through all relationship the player has, the new relationship is not included. How can I solve this issue?

(I can see in the Unity Editor that the relationship is establised under the player/faction member - NPC added to the relationship, but the relationsship is not updated in the FactionDatabase.)
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting Personal Affinity - but database not updated

Post by Tony Li »

Hi,

Here are a few things to check:

- Are there any errors or warnings in the Console window?
- Does your scene have a GameObject with a FactionManager component?
- Is your faction database assigned to the FactionManager component?
- Is a valid faction assigned to the FactionMember component associated with your factionMember variable?
haavard
Posts: 6
Joined: Thu Sep 29, 2022 12:49 am

Re: Setting Personal Affinity - but database not updated

Post by haavard »

Hi,
Thank you for the reply - feedback on the queries:

- Are there any errors or warnings in the Console window? Answer: No errors in the Console window
- Does your scene have a GameObject with a FactionManager component? Answer: yes, I have
- Is your faction database assigned to the FactionManager component? Answer: yes, the factiondatabase is assinged to the FactionManager
- Is a valid faction assigned to the FactionMember component associated with your factionMember variable? Answer: Yes, a valid faction is assigned to the FactionMember component
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting Personal Affinity - but database not updated

Post by Tony Li »

Hi,

Is "factionID" (the subject faction) valid?

In a copy of Love/Hate's Example scene, I added a test script with this method to the Princess GameObject:

Code: Select all

void Update()
{
    if (Input.GetKeyDown(KeyCode.F1))
    {
        var subjectID = FactionManager.instance.GetFactionID("Player");
        GetComponent<FactionMember>().SetPersonalAffinity(subjectID, 69);
    }
}

When I start the scene, the Princess's relationships look like this:

before.png
before.png (48.48 KiB) Viewed 2166 times

After I press [F1], it looks like this:

after.png
after.png (49.37 KiB) Viewed 2166 times

If that doesn't help, can you send a reproduction project to tony (at) pixelcrushers.com?
haavard
Posts: 6
Joined: Thu Sep 29, 2022 12:49 am

Re: Setting Personal Affinity - but database not updated

Post by haavard »

Thanks for the reply.

I get the same behaviour as you describes - the new relationship is added as you show, but the problem is that when I use factionMember.faction.relationships.Count the new relationship is not included. Do you know why?
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting Personal Affinity - but database not updated

Post by Tony Li »

Is it maybe an issue with where you're checking Count?

I set the test Update method to this:

Code: Select all

void Update()
{
    if (Input.GetKeyDown(KeyCode.F1))
    {
        var member = GetComponent<FactionMember>();
        Debug.Log(member.faction.relationships.Count);
        var subjectID = FactionManager.instance.GetFactionID("Player");
        member.SetPersonalAffinity(subjectID, 69);
        Debug.Log(member.faction.relationships.Count);
    }
}
And it prints this to the Console:

Code: Select all

3
4
In other words, the Princess has 3 relationships before adding the relationship to the Player, and 4 relationships after.
haavard
Posts: 6
Joined: Thu Sep 29, 2022 12:49 am

Re: Setting Personal Affinity - but database not updated

Post by haavard »

Thanks for the help - I see now what caused my problem. I set the relation in one script and do the count in another script. When I do the count in the same script as I set the relation, the count is correct.
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Setting Personal Affinity - but database not updated

Post by Tony Li »

Hi,

I'm glad you found the issue. Thanks for posting an update to let me know.
Post Reply