My targets dont clear. My code is the same as the instructors (I believe)

Not sure whats causing this to happen, been trying to debug for a while.

For future code pastes, please paste in the text of the script rather than a screenshot, as this will greatly improve readability. I’ll include a link to instructions for formatting the code text at the end of the reply.

The first thing we probably need to do is make sure that the Remove code is being called in the first place. Let’s add this Debug.Log to the RemoveTarget method:

Debug.Log($"Targeter.RemoveTarget({target})");

Its being called but only when on OnTriggerExit. When I switch states, only one is being deleted.

I may need some clarification…
If you target the sphere, it appears in the Cinemachine Target Group, then if you walk away, it’s removed
If you target the sphere, and you exit TargetingState by a different means it doesn’t get removed?

Paste in your PlayerTargetingState.cs. Be sure to paste the text itself, not a screenshot.

image
You are not running this code.

It must run when CurrentTarget != null, but you exit the method if it is

1 Like

The ! strikes again… @bixarrio has the right of it, methinks. That line should read

if(CurrentTarget==null)

not

if(CurrentTarget!=null)
1 Like

Privacy & Terms