Hello, I’m trying to use an OnTriggerEnter to build a list for the units, working on having an attack at will so they will auto-attack the closet unit, but it’s not working.
In the RPG project, I have the same code and setup and it works fine, was wondering if it had anything to do with the networking?
This is on a child object on the Unit and takes in the Unit’s Targeter.
Is this script on the same gameObject as the collider? I would try and drop in a a debug.log and try and figure out if your script has hold of the right collider, and from there see if you can figure out why it’s not getting triggered.
The script is on the child object that has a capsule collider, the right collider is being used, it’s not " is trigger " by default and is made trigger in Start. Have a Dbug.log in Start and onTriggerEnter, Start debug log prints but not the OnTriggerEnter.
Well, I can’t see a networking issue that would cause this. All the collisions are happening locally on the client. The only thing I could think of is if the server is refreshing the transform infrequently enough that the unit “jumps” over the boundary of the collider. Is OnTriggerStay() being triggered?
Nope, I tried removing the collider from the child object and using the one on the parent, that didn’t work.
Second I passed in a target Unit in the list to see if the OnTriggerStay foreach loop would work and it doesn’t even if there is a Unit in the list.
I was thinking maybe I had to do an OnSeverStart for the child object script, but making it a NetworkBehaviour caused it to have a networkID and I got errors for there being two on the parent object.
Also just tested having the Targeter take in the child object collider, this is in the OnServerStart
if (col)
{
col.isTrigger = true;
}
it works changing the child collider to a trigger but no collisions.
So was doing some more brainstorming wondering why the projectile works, but not this.
So I tried to Instantiate the child prefab object the same way as the projectile that’s network spawned, it works, the prefab is on the unit and the targeter still takes in the prefab collider.
The funny thing is the debug.log (Enter) is called when a projectile triggers it but the units don’t.
I don’t know why that is lol.
I have noticed that the Debug is called when the projectile hits the unit, I’m assuming that even tho I have the child gameobject’s collider referenced, the OnTriggerEnter is using the collider on the Parent gameobject
[SerializeField] private Collider col = null;
Tested this increasing the radius of the parent capsule collider on one unit, when a unit came close no trigger, but then I made one of the unit’s parent collider a trigger and it worked, still working it.
Think I have it now, it was the layer of the child collider. I had it change from default to another layer because the default blocked the raycast keeping me from clicking on the units, We changed the physics for all the layers so the other layers were not colliding and some blocked the raycast.
Making a new layer and checking the physics in the project settings should fix it, thanks for your patience