Found solution
event triggering one function, but not another
I stumbled upon a random problem I didnt think was possible. My game is a map strategy game, with countries visualy represented by tilemaps. Those tilemaps can be clicked, with an object that has a collider attached to it that follows the cursor. I decided to make a click of a country into an event, with an arguement of the country clicked. There are 2 listeners to the event, one in the same script as the event, its purpose is to simply Debug.Log(countryname) to monitor if everything is working fine. the 2nd one is an outside script that handles what to do with the clicks, currently it only has a "country selection" mechanism. Problem is that the debug does not work every single time. (It rarely even works) Visualy i can change my selected country, which is obvious with them changing color wherever i click, so the event is firing. But i only got the Debug message in the bottom of the screenshot after a 10th selection, countries triggering it are completly random. There is also another random problem of the USA being unclickable despite being the same as all other objects, which i dont seek an answer to in this post
Does anybody have the slightest idea what could be happening/Where to seek answers?
Here is the code of the events :
public event EventHandler OnClick;
public delegate void EventHandler(object? sender, OnClickEventArgs e);
public class OnClickEventArgs : EventArgs {
public CountryData country;
}
private void Onclick(object sender, OnClickEventArgs e) {
if (hoveringOver != null && myPosition.overUI == false) {
Debug.Log(hoveringOver.GetComponent<CountryData>().name);
}
}
void Start() {
OnClick += Onclick;
}
And Here is the function that is always triggered by the event :
private void OnClick(object sender, CursorMovement.OnClickEventArgs e) {
OnDispClickEventArgs args = new OnDispClickEventArgs(e.country, gm.players[displayedIdx]);
OnDispClick.Invoke(this, args);
}
private void Nothing(object sender, OnDispClickEventArgs e) {
}
Something Worth mentioning is that the collision system on tilemaps is shaky and does often change value from seing the tilemap collision and not seeing it due to every tile having its own collider, which might for some reason have an impact here.