Jump to content

Gestalt target tracking slight issue


hoxi
  • Pending

This function in both gestalt.lua and gestalt_guard_evolved.lua can cause a small issue:

local function SetTrackingTarget(inst, target, behaviour_level)
	local prev_target = inst.tracking_target
	inst.tracking_target = target
	inst.behaviour_level = behaviour_level
	if prev_target ~= inst.tracking_target then
		if inst.OnTrackingTargetRemoved ~= nil then
			inst:RemoveEventCallback("onremove", inst.OnTrackingTargetRemoved, prev_target)
			inst:RemoveEventCallback("death", inst.OnTrackingTargetRemoved, prev_target)
			inst.OnTrackingTargetRemoved = nil
		end
		if inst.tracking_target ~= nil then
			inst.OnTrackingTargetRemoved = function(_) inst.tracking_target = nil end
			inst:ListenForEvent("onremove", inst.OnTrackingTargetRemoved, inst.tracking_target)
			inst:ListenForEvent("death", inst.OnTrackingTargetRemoved, inst.tracking_target)
		end
	end
end

Simply setting inst.tracking_target to nil, but not removing the listeners means that, if the target player dies, and later despawns (or revives, then dies again), the removal listener will still fire and potentially set some other tracked target to nil.

 

The listeners function could look like this instead:

inst.OnTrackingTargetRemoved = function(_) SetTrackingTarget(inst, nil, inst.behaviour_level) end

This will do what's intended with all this setup, by removing the tracked target as usual, but also the listeners, and keep behavior level as it was (as other things handle it).


Steps to Reproduce

See above.

  • Like 1



User Feedback


There are no comments to display.



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...