Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua: fix non-const TArray outparams being skipped in UFunction property pushers #754

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lyrth
Copy link
Contributor

@Lyrth Lyrth commented Jan 13, 2025

Description

UFunction parameters that has type TArray<...>& discards the value passed from Lua for it, making the UFunction receive an empty array, or shifts the argument list and messes up parameter ordering.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

/Script/Engine.KismetStringLibrary:CullArray and /Script/UMG.WidgetBlueprintLibrary:GetAllWidgetsOfClass are used to check if the parameters were passed correctly, by hooking into them and calling them from Lua.

Testing

Test code:

-- int32 CullArray(FString SourceString, TArray<FString>& inArray)
RegisterHook("/Script/Engine.KismetStringLibrary:CullArray", function (Context, SourceString, InArray)
    print(">> CullArray call")

    local str = SourceString:get()
    print(("String: '%s'"):format(str:ToString()))

    local arr = InArray:get()
    print(("Array: __len %d, num %d, %016x %016x"):format(#arr, arr:GetArrayNum(), arr:GetArrayAddress(), arr:GetArrayDataAddress()))
    for i = 1, #arr do
        print("  "..i, arr[i]:ToString())
    end

    print("<< CullArray")
    print()
end)

-- void GetAllWidgetsOfClass(class UObject* WorldContextObject, TArray<class UUserWidget*>& FoundWidgets, TSubclassOf<class UUserWidget> WidgetClass, bool TopLevelOnly);
RegisterHook("/Script/UMG.WidgetBlueprintLibrary:GetAllWidgetsOfClass", function (Context, WorldContextObject, FoundWidgets, WidgetClass, TopLevelOnly)
    print(">> GetAllWidgetsOfClass call")

    local world = WorldContextObject:get()
    print(("World: '%s'"):format(world))

    local arr = FoundWidgets:get()
    print(("Array: __len %d, num %d, %016x %016x"):format(#arr, arr:GetArrayNum(), arr:GetArrayAddress(), arr:GetArrayDataAddress()))

    local class = WidgetClass:get()
    print(("Class: '%s'"):format(class))

    local bool = TopLevelOnly:get()
    print(("TopLevelOnly: '%s'"):format(bool))

    print("<< GetAllWidgetsOfClass")
    print()
end)



ExecuteInGameThread(function()
    local ksl = StaticFindObject("/Script/Engine.Default__KismetStringLibrary")

    local arr = {
        "aaa",
        "bbb",
        "",
        "world",
        "",
        "",
        "ccc"
    }
    print("** Before cull:")
    for i = 1, #arr do
        print("  "..i, arr[i])
    end
    print()

    local elLeft = ksl:CullArray("hello", arr)
    ---@cast arr RemoteUnrealParam<FString>

    print("** After cull:")
    for i = 1, elLeft do
        print("  "..i, arr[i]:get():ToString())
    end

    print("----------")
    print()
end)

ExecuteInGameThread(function()
    local wbl = StaticFindObject("/Script/UMG.Default__WidgetBlueprintLibrary")

    local world = require "UEHelpers".GetWorld()
    local widget = StaticFindObject("/Script/UMG.UserWidget")
    local foundArr = { }

    for _ = 1,69 do StaticConstructObject(widget, world) end

    wbl:GetAllWidgetsOfClass(world, foundArr, widget, false)

    print("** Found widgets: ", #foundArr)
    print("----------")
    print()
end)

Original behavior:
image

This change:
image

Checklist

  • I have added the necessary description of this PR to the changelog, and I have followed the same format as other entries.

Notes

A similar change (and also to line 249) may be needed once TMap and TSet support gets in.

@Lyrth Lyrth force-pushed the fix-non_const_tarray_param branch 2 times, most recently from abeb68e to 7190c89 Compare January 13, 2025 12:17
assets/Changelog.md Outdated Show resolved Hide resolved
@Lyrth Lyrth force-pushed the fix-non_const_tarray_param branch from 7190c89 to 345736a Compare January 13, 2025 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants