Question about relationship

Announcements, support questions, and discussion for Love/Hate.
Post Reply
zebialowicz.s
Posts: 2
Joined: Sun Jul 28, 2024 5:26 am

Question about relationship

Post by zebialowicz.s »

Hi!
Im long user of Dialogue System and now i have to start using also Love/Hate :)
However i think i don't fully inderstand the concept behind it.

What i'm trying to achieve is that:
- My game can randomly spawn/generate hundreds of units in the game. Each unit of course can be gameobject/i'm tracking state of every unit in the game and im applying that on the spawn.
- Now every single unit in my game can for example trade with the player. So player can buy something from a unit, or sell something.
- My every unit is described with the name like unit_12342345 where numbers are just generated code based on my grid graph.
- Now in Love/Hate i have basic relationship called Affinity and 2 factions: Player, Traders
- Each unity has component FactionMember with Traders selected as Faction
- After each transaction with unit i want to modify relationship between THAT unit and the player. So if you are buying more from the same unity, the better prices You will have, based on the affinity. So imagine that each transaction increases affinity by 0.1 BUT only towards that specific unit.

And now i have problem. I tried to use this code:

Code: Select all

int affinityID = FactionManager.instance.factionDatabase.GetRelationshipTraitID("Affinity");
            FactionManager.instance.factionDatabase.ModifyPersonalRelationshipTrait(gameObject.name, "CharacterPlayer", affinityID, 0.1f);

var affinityValue = FactionManager.instance.GetAffinity(gameObject.name, "CharacterPlayer");
            
Debug.Log($"Affinity from {gameObject.name} to Player is: {affinityValue}");
But the problem is it never changes. And i think it never changes because there is no faction with name: unit_12342345.
FindFaction always return -1 in that case.

Does it mean i would have to make hundreds or thousands of faction, for every single unit in my game to support it?
Or can i have just one faction called Traders and have relation towards FactionMember?

Best
User avatar
Tony Li
Posts: 22085
Joined: Thu Jul 18, 2013 1:27 pm

Re: Question about relationship

Post by Tony Li »

Hi,

If you have hundreds of traders and want each one to have its own unique relationship (i.e., faction) with the player, you must make a unique faction for each trader.

You don't need to do this manually. When you generate your trader, you can generate a corresponding faction and set the trader's FactionManager component to use that faction. For instructions and code, please see: How To: Create Factions At Runtime.

I test Love/Hate with 10,000 simultaneous faction members, so performance shouldn't be a concern.
Post Reply