Problem "yield break" and "weakreference"
"yield break;" has a problem;
example
IEnumerator A()
{
Debug.Log("A Start");
yield break;
Debug.Log"A End");
}
IEnumerator B()
{
Debug.Log("B Start");
yield StartCoroutine(A());
Debug.Log("B End");
}
public Class Test : Monobehivor
{
public WeakReference pt;
void Start()
{
pt = new System.WeakReference(StartCoroutine(B()));
}
void Update()
{
if (pt.Target == null)
{
Debug.Log("Reset");
}
}
}
that result is ...
"B Start" "A Start" "Reset" "B End"
the problem is that the weakreference of B function is reset on the "yield StartCoroutine(A());" (pt.Target is null) and the "Debug.Log("B End") is call ...
Comment
Your answer
Follow this Question
Related Questions
MonoDevelop Unity API reference function with wrong path. How to Fix it? 1 Answer
c# Object reference not set to an instance of an object 1 Answer
Can't access a method from another script (Object reference not set to an instance of an object) 1 Answer
How do I reference int from other script 0 Answers
How do I access another script in Unity C# 2018.2? 0 Answers