I am suddenly unable to get OnTriggerEnter to fire on my dedicated server. It used to work, and I can use “if IsServer” to test the script at network spawn and other areas, and they all call as expected. It just refuses to call OnTriggerEnter on the server. IsTrigger is selected on the collider, there is a rigidbody, I have even checked the collider.isTrigger and collider.enabled statuses in the script. The OnTriggerEnter calls on clients as well, just not the server. Any ideas?
What’s your code?
You should log whether there is an actual overlap and that the layers of the objects are what you think they are. Use logging or the debugger to verify.
Thank you for your quick reply. Your response suggests that I wasn’t clear about what is happening. I will try to describe it in another way…
When a scene loads on my dedicated server, it spawns in network objects on the server. When these are spawned, they call code on the server (if (IsServer)…) as well as on clients. That works fine. After a delay, other functions are called that call code on the server and clients as well. Those all work fine as well. When the player collides with one of these objects, the OnTriggerEnter is called on the clients, but not the server. This has worked fine for months, and now it simply refuses to call OnTriggerEnter on the server at all. If it were a layer issue it would not be calling on the clients. If there wasn’t “actual overlap” the clients would not be triggering properly. Also, I do not believe this is related to my code, because other network spawned objects (that have not changed in months) are now suddenly having the same problem. It’s like I turned off some “call OnTriggerEnter on server” option or something. Are you aware of any Unity settings that may cause this?
No, nothing besides the general rules for physics collider/trigger interaction.
“It worked for months” doesn’t rule out a simple issue with the project be it asset, code or settings and for some reason it only affects the server build. You did check logs for any exceptions?
There’s also a possibility that server build is not in sync with client builds, ie using different sets of assets perhaps.
If nothing helps I’d try to construct a simple test case and add lots of logging. Including layers because those do affect collision behaviour and you want to be sure, not assume, that it the layer settings are correct on the server. Just because it works on clients is no guarantee it will be the same on the server - if the inexplicable occurs you have to verify every dumb thing because it’s often the unexpected that does occur that eventually leads to finding the issue.
Well, it’s been a while since I felt this derp. The moment I woke up today, I sat and thought about it intently for 30 seconds and realized what happened. Not long ago I was optimizing a lot of my scripts. It turns out during optimization, a single line of code did not get transferred to the new system. That line happened to be the line that enabled the player’s body on the server. The players body is where the player’s collider is of course. So yeah, I was not enabling the body/collider of the player specifically on the server. (sigh) I love coding Thank you for your responses.