Skip to content

feat: Add 'IsValidField'#1324

Merged
wildcherry2 merged 2 commits into
mainfrom
lms-index-mm-fix-3
Jul 4, 2026
Merged

feat: Add 'IsValidField'#1324
wildcherry2 merged 2 commits into
mainfrom
lms-index-mm-fix-3

Conversation

@UE4SS

@UE4SS UE4SS commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds 'IsValidField' to RemoteObject, including UObject.
It returns true if the field (i.e. property or function) exists in the UObject regardless if IsValid would return false because of a nullptr.

See test section for example of usage.

Fixes #1284

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How has this been tested?

Run this code when GameModeBase exists.
For me in Palworld, that's at the main menu.

RegisterKeyBind(Key.K, {ModifierKey.CONTROL}, function()
    local GameMode = FindFirstOf("GameModeBase")
    if GameMode:IsValid() then
        print(string.format("GameMode: %s\n", GameMode:GetFullName()))
    else
        print("GameMode not valid\n")
        return
    end

    if GameMode.aaa:IsValidField() then
        print("aaa:IsValidField(): YES\n")
    else
        print("aaa:IsValidField(): NO\n")
    end
    if GameMode.aaa:IsValid() then
        print("aaa:IsValid(): YES\n")
    else
        print("aaa:IsValid(): NO\n")
    end

    if GameMode.GameState:IsValidField() then
        print("GameState:IsValidField(): YES\n")
    else
        print("GameState:IsValidField(): NO\n")
    end
    if GameMode.GameState:IsValid() then
        print("GameState:IsValid(): YES\n")
    else
        print("GameState:IsValid(): NO\n")
    end
    GameMode.GameState = nil
    if GameMode.GameState:IsValidField() then
        print("GameState:IsValidField(): YES\n")
    else
        print("GameState:IsValidField(): NO\n")
    end
    if GameMode.GameState:IsValid() then
        print("GameState:IsValid(): YES\n")
    else
        print("GameState:IsValid(): NO\n")
    end
end)

Expected outcome:

aaa:IsReflected(): NO
aaa:IsValid(): NO
GameState:IsReflected(): YES
GameState:IsValid(): YES
GameState:IsReflected(): YES
GameState:IsValid(): NO

You can create a universal function that can handle LocalObject as well, if you want that for some reason:

local function IsValidField(Object, Field)
    if type(Field) ~= "string" then return false end
    if Object[Field].IsValidField then
        return Object[Field]:IsValidField()
    else
        return Object[Field]
    end
end

UE4SS added 2 commits July 2, 2026 22:52
For example, `FText("Test").aaa` would return a reference of the same FText that tried to access `aaa` instead of nil
This returns true if the field is a valid in a UObject, even if 'IsValid' would return false because of a nullptr.
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
CMAKE-Game__Shipping__Win64 Download Logs
Build Details
Name Information
PR Commit f6ec6a7
Merge Commit e0e8bd9
Size 41.74 MB
Last Updated Jul 2, 26, 9:26:34 PM UTC
Expires At Jul 16, 26, 9:26:30 PM UTC

CMAKE-Game__Debug__Win64 Download Logs
Build Details
Name Information
PR Commit f6ec6a7
Merge Commit e0e8bd9
Size 41.75 MB
Last Updated Jul 2, 26, 9:21:09 PM UTC
Expires At Jul 16, 26, 9:21:05 PM UTC

@wildcherry2
wildcherry2 merged commit 68dd45c into main Jul 4, 2026
11 of 15 checks passed
@wildcherry2
wildcherry2 deleted the lms-index-mm-fix-3 branch July 4, 2026 16:53
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.

[BUG - Release] LUA: Impossible to check if "userdata" variable has a property or method

2 participants