[JUST SKIP TILL THE END PLEASE… THE VERY LAST EDIT HAS A PROBLEM I’M STILL TRYING TO SOLVE!]
[TLDR: I seek a solution to push out notifications to the player RIGHT BEFORE gathering Resources, rather than whenever he enters a trigger zone of a tree or something, because… well… in a forest, that’s not only a serious performance issue waiting to happen, but also a serious annoyance to the players]
OK so as I continue on my quest of implementing Notification Systems in my game, Resource Gathering is no slouch in this area either.
I did some research (and Debugging) through my code, trying to seek exactly where in the world do I place my code to trigger the action that calls the Resource Gathering behaviour, and I found it in ‘InputReader.cs’, as shown below (you may think that it doesn’t do the job for repeated animations with the new third-person architecture, but I assure you for my use cases it’ll work perfectly fine… Until I decide an object is no longer stackable):
public void OnInteractWithResource(InputAction.CallbackContext context)
{
if (context.performed) {
InteractWithResourceEvent?.Invoke();
IsResourceGathering = true;
}
else if (context.canceled) IsResourceGathering = false;
}
and this is the caller for the event trigger, in ‘PlayerFreeLookState.cs’:
private void InputReader_HandleResourceGatheringEvent()
{
if (stateMachine.ResourceFinder.FindNearestTarget())
{
// I know the code I want to implement goes in here, I just don't know how to get the resource to implement what I want here...
PlayerGatheringState nextState = new PlayerGatheringState(stateMachine, stateMachine.ResourceFinder.CurrentTarget, stateMachine.GetComponent<ResourceGatherer>());
stateMachine.SwitchState(new PlayerFacingState(stateMachine, stateMachine.ResourceFinder.CurrentTarget.transform.position, nextState));
}
}
But now I have a problem… To properly implement a notification RIGHT BEFORE gathering, I have to find a way to refer to the resource that he is about to interact with (and with many resources in the scene, a function like ‘FindObjectsOfType<…>()’ just won’t cut it!)… How do I do that?
(And yes, I tried implementing the notification system in ‘IsValid()’ (for our third person), but this one turned into pure catastrophe, because if the player goes into a forest of trees, a minefield, or maybe a popular fishing spot for this case, with resources surrounding them literally everywhere, you can imagine how crazy the Notification system will get).