OnObjectDetected event

gurayg

Member
Hi @Justin
I'm using an interact ability that is using Raycast for detection.
I want to use OnObjectDetected whenever the ability detects an object (for a custom object highlighting) but the problem is,
"DetectedObject" is set when raycast hits an object + if the Ability' "Ability Message Text" is not empty.

Can't say for certain if this is a bug but controller functionality works differently (setting DetectedObject) based on "Ability Message Text"

I've taken a look at the code and noticed this line
m_CheckForAbilityMessage = !string.IsNullOrEmpty(m_AbilityMessageText) || m_AbilityMessageIcon != null;
in Ability.cs

If I set the m_CheckForAbilityMessage to true by force, DetectedObject is set when raycast hits and thus OnObjectDetected event is fired.

I would make a copy of Interact ability and set m_CheckForAbilityMessage to true but Initialize method is not virtual and I don't want to change base class code.

What do you think is happening? How should I make this work for me?
 
Thanks,
That would work for me. Would it be online for next update? If so, I'll do it on my end.
I'm also still wandering why you did it that way. Maybe my approach is wrong.
Do you remember why you made it so "DetectedObject" gets set earlier, if "Ability Message Text" is not empty?
 
I'm looking at this now. Where do you see m_CheckForAbilityMessage blocking the DetectedObject setter? The DetectedObject is set within DetectObjectAbilityBase.CanStartAbility and none of this is based on CheckForAbilityMessage.
 
Hi @Justin
Can't check the code right now. But I remember 2 things about the issue.

You should see it behaves differently if you have a string in the field or not.

I remember a series of properties being set in init.

And that you'll have to set the field at edit time.

I'll check in about an hour.
 
I can't tell you the whole story here. What I can tell is

This is in Ability Initialize method:
m_CheckForAbilityMessage = !string.IsNullOrEmpty(m_AbilityMessageText) || m_AbilityMessageIcon != null;
sets CheckForAbilityMessage to false. Which is used in UpdateAbilities of UCCLocomotion. (this might be the problem, not sure)

There is also AbilityMessageText which sets m_CheckForAbilityMessage. or maybe this is causing the problem.

Here is what I saw when I tested the DetectedObject:
If there is an Ability Message Text set (and we're using raycast) DetectedObject is set before we use an input. Just like you would expect it to work.
We detected an object but haven't started the ability.
But if Message text is empty, DetectedObject is not set when raycast detects an object but it is set when we use an input.

I know it is not much of an help. I couldn't figure out exactly what is going on here :)
 
In the demo scene I removed the ability message text from the Drive ability. I then went to the car and started the ability - the event was sent.

I see what is happening though. The event gets sent when DetectedObject is set, and the DetectedObject is reevaluated every InactiveUpdate when the ability message text is sent. So in your case you can continue as you are by enabling m_CheckForAbility message, or override InactiveUpdate within your own ability to have it checked.
 
Back
Top