Search Unity

help with method overloading

Discussion in 'Editor & General Support' started by Deadly_fallout, Mar 31, 2019.

  1. Deadly_fallout

    Deadly_fallout

    Joined:
    Jul 17, 2018
    Posts:
    7
    Code (CSharp):
    1. [I][COLOR=#ff0000]private void OnParticleCollisionManual(GameObject other, int aliveParticles = -1)[/COLOR][/I]
    2.     {
    3.         collisionEvents.Clear();
    4.         var aliveEvents = initiatorPS.GetCollisionEvents(other, collisionEvents);
    5.         for (int i = 0; i < aliveEvents; i++)
    6.         {
    7.             var angle = Vector3.Angle(collisionEvents[i].normal, Vector3.up);
    8.             if (angle > MaxGroundAngleDeviation) continue;
    9.             if (InstantiateWhenZeroSpeed)
    10.             {
    11.                 if (collisionEvents[i].velocity.sqrMagnitude > 0.1f) continue;
    12.                 var isNearDistance = false;
    13.                 for (int j = 0; j < aliveParticles; j++)
    14.                 {
    15.                     var distance = Vector3.Distance(collisionEvents[i].intersection, particles[j].position);
    16.                     if (distance < MinDistanceBetweenDecals) isNearDistance = true;
    17.                 }
    18.                 if (isNearDistance) continue;
    19.             }
    20.             var emiter = new ParticleSystem.EmitParams();
    21.             emiter.position = collisionEvents[i].intersection + collisionEvents[i].normal * MinDistanceBetweenSurface;
    22.             var rotation = Quaternion.LookRotation(-collisionEvents[i].normal).eulerAngles;
    23.             rotation.z = Random.Range(0, 360);
    24.             emiter.rotation3D = rotation;
    25.  
    26.             DecalParticles.Emit(emiter, 1);
    27.         }
    28.     }
    Code (CSharp):
    1. void OnParticleCollision(GameObject other)
    2.     {
    3.         if (InstantiateWhenZeroSpeed)
    4.         {
    5.             if (!collidedGameObjects.Contains(other))
    6.                [I][COLOR=#ff0000] collidedGameObjects.Add(other);[/COLOR][/I]
    7.         }
    8.         else
    9.         {
    10.             OnParticleCollisionManual(other);
    11.         }
    12.     }
    13. }
    I cant use default parameters and these 2 functions use it. I need to change them to not use default parameters. I heard of method overloading, but when i tried i couldnt get it to work. Can someone help me with it?

    Edit: the code snippets that have "color" in front of them are the issue.
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Unfortunately, callback methods cannot be overloaded. In order for this to work, the Unity developers would have to modify the MonoBehavior class and implement the new overloaded method.