How to link HealthBar to Enemy?

The task seems to be very simple since the healthbar object has an attribute monitor on it and it simply has a "character" variable which I thought you could plug in the enemy character and his health would be monitored instead. However, I do not seem to be able to get it to work. Interestingly the monitor was working for the player even before I had the player assigned to the "character".

How can I make a health bar work for an enemy character?

Thanks.
 
Can you place a breakpoint within AttribeMonitor.OnAttachCharacter? The character should be your enemy GameObject.
 
Last edited:
The breakpoint at line 54 does work when there is not character attached to the monitor. (I do not understand what in the code makes it find the player by default)

The breakpoint does not trigger if I attach the enemy character to it, and I get the following error:

Error: The UI element Health (Player) cannot find a character.
UnityEngine.Debug:LogError(Object)
Opsive.UltimateCharacterController.UI.CharacterMonitor:Awake() (at Assets/Opsive/UltimateCharacterController/Scripts/UI/CharacterMonitor.cs:47)
Opsive.UltimateCharacterController.UI.AttributeMonitor:Awake() (at Assets/Opsive/UltimateCharacterController/Scripts/UI/AttributeMonitor.cs:38)

And these are what I had in the call stack when I placed the break point at line 54 (game did not stop or the line turn yellow)

> Void Opsive.UltimateCharacterController.UI.AttributeMonitor:OnAttachCharacter (GameObject)+0x30 at C:\(S)OA\UCC Test\Assets\Opsive\UltimateCharacterController\Scripts\UI\AttributeMonitor.cs:54 C# Symbols loaded.

Void Opsive.UltimateCharacterController.UI.CharacterMonitor:OnDestroy ()+0x3 at C:\(S)OA\UCC Test\Assets\Opsive\UltimateCharacterController\Scripts\UI\CharacterMonitor.cs:105 C# Symbols loaded.

Void Opsive.UltimateCharacterController.UI.AttributeMonitor:OnDestroy ()+0x2 at C:\(S)OA\UCC Test\Assets\Opsive\UltimateCharacterController\Scripts\UI\AttributeMonitor.cs:95 C# Symbols loaded.
 
I created a new scene and assigned an enemy character to the attribute monitor and it correctly referenced the enemy character. The stack trace that you posted relates to when the game ends so that looks good.
 
I just tried this again in the Behavior Designer 3rd Person Melee Demo scene, and assigned the Agent Nolan character to the Attribute Manager. Here is what it looks like:
1541033326846.png

The health does not update when I attack AgentNolan character. It does work when there is no character assigned, and it monitors the player's health. Do I seem to be doing the same thing as you did, or am I missing something?
 
I created a blank scene and just added the character and the ai agent when I tested it. The behavior designer scene does some extra setup so I wouldn't use that as a base.
 
Ok. I created a new UCC scene and added a brand new Player and AI agent. Here is what I found after assigning the enemy character to the health attribute monitor:

- If the player is disabled, and if i l let the AI agent fall, the health bar will update accordingly
- If the player is in the scene activated, then the healthbar does not update

In my own game scene though, even if I created a brand new AI character, and even if I disable my player character, the bar does not update.

I tried adding a Debug.Log right after base.OnAttachCharacter(character), and I do see it being executed. But I am also getting the following error message:

Error: The UI element Health cannot find a character.
UnityEngine.Debug:LogError(Object)
Opsive.UltimateCharacterController.UI.CharacterMonitor:Awake() (at Assets/Opsive/UltimateCharacterController/Scripts/UI/CharacterMonitor.cs:47)
Opsive.UltimateCharacterController.UI.AttributeMonitor:Awake() (at Assets/Opsive/UltimateCharacterController/Scripts/UI/AttributeMonitor.cs:38)

I cannot really see what is going on.

Why does the monitor track the player when character is null in the first place? There is no reference to the player tag in the entire code for the Attribute Monitor, or the HealthFlashMonitor. What makes it choose the player automatically? From the clean scene it does look like the problem is having the player in the scene.
 
Top