Working on a a Unity project and I'm caching an GameObject reference via its implemented interface at the start of my coroutine. For some reason, this variable is "out of scope" when I debug it. This causes any variable that references it (like the boolean below it) to be out of scope as well. I've tried a number of fixes, from updating VS2019, to ensuring all projects are set to start up when attaching to Unity to debug. I've tried every fix that applied to my issue suggested here:
Visual Studio 2015 Debugging: Can't expand local variables?
Nothing I do allows me to scrutinize this variable or anything associated with it. It doesn't show up in the Locals window. I'm not sure what I'm missing here, but it's been a real pain to debug this code. Any help would be appreciated!
EDIT: Provided code sample:
private IEnumerator TranslateTouchableNew(Touchable translator, OffsetTransform destination)
{
bool hasArrived = false;
ITouchTranslationProfile profile = translator.TranslationProfile;
bool hasProfile = (profile != null);
//Translator position vars
Vector3 positionBeforeYArcOffset = translator.transform.position;
Vector3 newPosition;
Vector3 normalizedHeading = Vector3.zero;
//Destination & Distance
Vector3 destinationWithOffsets = CalculateDestinationWithOffsets();
float startingDistance = (destinationWithOffsets - positionBeforeYArcOffset).magnitude; //Length between the translator transform and the final destinatin vector after considering receptacle offset and translator mesh offset
float currentDistance = startingDistance;
float distanceCoveredPercent;
//Applying profile values, if they exist; otherwise use default values for speed and arc
AnimationCurve yArc = hasProfile && profile.YArcOverride != null ? profile.YArcOverride : standardYArcOffset;
float yArcProximityFactor = yArcByProximityFactor.Evaluate(startingDistance);
float speed = hasProfile ? metersPerSecond * profile.SpeedScalePercent : metersPerSecond;
while (!hasArrived)
{
//Skip standard translator logic for custom implementation on the translator
if (hasProfile && profile.UseCustomTranslation) hasArrived = profile.CustomTranslateUntilArrived(destination);
else
{
//Calculate the final destination. Because the destination is transform based (it can move), this needs to be done every frame.
destinationWithOffsets = CalculateDestinationWithOffsets();
//This is needed to get an accurate calculation on distance covered BEFORE applying the Y Arc offset, which interferes with the actual length calculated by GetCurrentDistance()
//translator.transform.position = positionBeforeOffset;
currentDistance = (destinationWithOffsets - positionBeforeYArcOffset).magnitude;
//Closer the translator is to the destination, the higher the percent
distanceCoveredPercent = 1 - (currentDistance / startingDistance);
///Application of max speed (after application of <see cref="ITouchTranslationProfile.SpeedScalePercent"/>), by total distance proximity
float speedFactor = speedByProximityFactor.Evaluate(distanceCoveredPercent);
newPosition = Vector3.MoveTowards(translator.transform.position, destinationWithOffsets, (speed * speedFactor) * Time.deltaTime);
LogVector3Explicit(newPosition, "position before YArc:");
positionBeforeYArcOffset = newPosition;//Set this for next frame so that CurrentDistance can be accurately calculated
SetArcOffsetOnNewPosition();//Apply YArc to the previously calculated NewPosition
LogVector3Explicit(newPosition, "position after YArc:");
translator.transform.position = newPosition;
if (distanceCoveredPercent < 0.99f) normalizedHeading = (destinationWithOffsets - translator.transform.position).normalized;//Set the heading if we're almost done with translation
if (hasProfile) profile.TranslationPercentComplete = distanceCoveredPercent; //translator may use this data for its own calculations
if (distanceCoveredPercent >= 1.0f) hasArrived = true;
}
yield return null;
}
if (hasProfile) profile.OnArrival(normalizedHeading, speed);
CoroutineByTranslator.Remove(translator);
void SetArcOffsetOnNewPosition()
{
float yOffset = yArc.Evaluate(currentDistance);
yOffset *= yArcProximityFactor;
newPosition.y += yOffset;
}
Vector3 CalculateDestinationWithOffsets()
{
Vector3 finalPosition = destination.Transform.position + destination.Offset;
if (hasProfile) finalPosition.y += profile.TransformToMeshEndLength;
return finalPosition;
}
void LogVector3Explicit(Vector3 logMe, string name)
{
Debug.Log(name + " : " + logMe.x + ", " + logMe.y + ", " + logMe.z);
}
}
Assigning "Profile" from the provided Touchable translator (translator implements Monobehavior and has a reference to the component that implements ITouchTranslatorProfile) is the variable in question.
Here's the breakpointed code sample to help illustrate the issue I'm having while debugging (see Watch window):