在使用DrawText时候用Project将世界坐标转化为屏幕坐标,这就出现了问题,text会同时出现在屏幕前和后边

  

FVector ScreenPos = Project(data.Position);

if (ScreenPos.Z == 0)
{
//behind the screen
return;
}

  返回的FVector,如果behind the screen 则为0,否则不为0,在源码里边可以看到

FVector UCanvas::Project(FVector Location) const
{
    FPlane V(0,0,0,0);

    if (SceneView != NULL)
    {
        Location.DiagnosticCheckNaN();
        V = SceneView->Project(Location);
    }

    FVector resultVec(V);
    resultVec.X = (ClipX/2.f) + (resultVec.X*(ClipX/2.f));
    resultVec.Y *= -1.f * GProjectionSignY;
    resultVec.Y = (ClipY/2.f) + (resultVec.Y*(ClipY/2.f));

    // if behind the screen, clamp depth to the screen
    if (V.W <= 0.0f)    
    {
        resultVec.Z = 0.0f;
    }
    return resultVec;
}