C# Ambiguity problem with default overloads
Hello I'm having a problem where I keep getting ambiguity warnings about a overloaded method with defaults, here is the overloaded code:
public static T Spawn<T>(this T prefab, Vector3? position = null, Quaternion? rotation = null, bool force = false) where T : Component {
return ObjectPool.instance.Spawn(prefab.gameObject, position, rotation, force).GetComponent<T>();
}
public static GameObject Spawn(this GameObject prefab, Vector3? position = null, Quaternion? rotation = null, bool force = false) {
return ObjectPool.instance.Spawn(prefab, position, rotation, force);
}
And this is how I call it:
public GameObject pooledObject;
void Update () {
if (Input.GetKeyDown(KeyCode.Space)) {
GameObject spawned = pooledObject.Spawn();
}
}
The Unity error:
Assets/Scripts/Test.cs(9,47): error CS0121: The call is ambiguous between the following methods or properties:
ObjectPoolExtensions.Spawn(this UnityEngine.GameObject, UnityEngine.Vector3?, UnityEngine.Quaternion?, bool)' and
ObjectPoolExtensions.Spawn(this UnityEngine.GameObject, UnityEngine.Vector3?, UnityEngine.Quaternion?, bool)'
Your answer
Follow this Question
Related Questions
Referencing uninstantiated GameObject within a class? 0 Answers
How to make list of methods (example Sims) 1 Answer
Arbitrary line in one method prevents another for working? 1 Answer
change selected state between x gameobjects 0 Answers
C# Touch Input with Raycast on Interactive Map to toggle Canvas 0 Answers