Skip to content

Commit 41a5e8f

Browse files
committed
Add support for calling GetComponent<T> on GameObjects
- Add support for calling GetComponent<T> on gameobjects by getting their transform component internally and calling it on that.
1 parent 4b95af9 commit 41a5e8f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,22 @@ private SymbolDefinition InvokeExtern(SymbolDefinition[] invokeParams)
661661

662662
// Now make the needed symbol definitions and run the invoke
663663
if (!targetMethod.IsStatic && !(targetMethod is ConstructorInfo)/* && targetMethod.Name != "Instantiate"*/) // Constructors don't take an instance argument, but are still classified as an instance method
664-
visitorContext.uasmBuilder.AddPush(accessSymbol);
664+
{
665+
if (genericTypeArguments != null && typeof(GameObject).IsAssignableFrom(accessSymbol.symbolCsType)) // Handle GetComponent<T> on gameobjects by getting their transform first
666+
{
667+
using (ExpressionCaptureScope transformComponentGetScope = new ExpressionCaptureScope(visitorContext, null))
668+
{
669+
transformComponentGetScope.SetToLocalSymbol(accessSymbol);
670+
transformComponentGetScope.ResolveAccessToken("transform");
671+
672+
visitorContext.uasmBuilder.AddPush(transformComponentGetScope.ExecuteGet());
673+
}
674+
}
675+
else
676+
{
677+
visitorContext.uasmBuilder.AddPush(accessSymbol);
678+
}
679+
}
665680

666681
foreach (SymbolDefinition invokeParam in expandedParams)
667682
visitorContext.uasmBuilder.AddPush(invokeParam);

0 commit comments

Comments
 (0)