Page 1 of 1

Setting Personal Affinity - but database not updated

Posted: Fri Aug 02, 2024 7:18 am
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.)

Re: Setting Personal Affinity - but database not updated

Posted: Fri Aug 02, 2024 8:35 am
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?

Re: Setting Personal Affinity - but database not updated

Posted: Fri Aug 02, 2024 9:05 am
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

Re: Setting Personal Affinity - but database not updated

Posted: Fri Aug 02, 2024 10:26 am
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 1987 times

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

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

If that doesn't help, can you send a reproduction project to tony (at) pixelcrushers.com?

Re: Setting Personal Affinity - but database not updated

Posted: Sat Aug 03, 2024 3:23 am
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?

Re: Setting Personal Affinity - but database not updated

Posted: Sat Aug 03, 2024 1:42 pm
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.

Re: Setting Personal Affinity - but database not updated

Posted: Sun Aug 04, 2024 3:21 am
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.

Re: Setting Personal Affinity - but database not updated

Posted: Sun Aug 04, 2024 8:47 am
by Tony Li
Hi,

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