Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
Fix bug with using GetComponent<User T> on game objects
Browse files Browse the repository at this point in the history
- The code was falsely attempting to get components on a transform using the gameobject version since the underlying gameobject was incorrectly being converted to a transform
  • Loading branch information
MerlinVR committed Mar 19, 2020
1 parent d72ce7b commit bd0a905
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,11 +1111,12 @@ private SymbolDefinition InvokeExtern(SymbolDefinition[] invokeParams)
}

SymbolDefinition[] expandedParams = GetExpandedInvokeParams(targetMethod, invokeParams);
bool isUserTypeGetComponent = targetMethod.Name.StartsWith("GetComponent") && genericTypeArguments != null && genericTypeArguments.First().IsSubclassOf(typeof(UdonSharpBehaviour));

// Now make the needed symbol definitions and run the invoke
if (!targetMethod.IsStatic && !(targetMethod is ConstructorInfo)/* && targetMethod.Name != "Instantiate"*/) // Constructors don't take an instance argument, but are still classified as an instance method
{
if (genericTypeArguments != null && typeof(GameObject).IsAssignableFrom(accessSymbol.symbolCsType)) // Handle GetComponent<T> on gameobjects by getting their transform first
if (genericTypeArguments != null && typeof(GameObject).IsAssignableFrom(accessSymbol.symbolCsType) && !isUserTypeGetComponent) // Handle GetComponent<T> on gameobjects by getting their transform first
{
using (ExpressionCaptureScope transformComponentGetScope = new ExpressionCaptureScope(visitorContext, null))
{
Expand All @@ -1142,8 +1143,7 @@ private SymbolDefinition InvokeExtern(SymbolDefinition[] invokeParams)
else
throw new System.Exception("Invalid target method type");

if (targetMethod.Name.StartsWith("GetComponent") &&
genericTypeArguments != null && genericTypeArguments.First().IsSubclassOf(typeof(UdonSharpBehaviour)))
if (isUserTypeGetComponent)
{
returnSymbol = HandleGenericUSharpGetComponent(targetMethod as MethodInfo, genericTypeArguments.First(), invokeParams);
}
Expand Down

0 comments on commit bd0a905

Please sign in to comment.