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

Dynamic Binding not working correctly v2.3.6, UE5.3 #678

Open
V2iDanAbend opened this issue Nov 17, 2023 · 2 comments
Open

Dynamic Binding not working correctly v2.3.6, UE5.3 #678

V2iDanAbend opened this issue Nov 17, 2023 · 2 comments

Comments

@V2iDanAbend
Copy link

Hi,

The Dynamic Binding functionality is not working correctly anymore. For example, in this test, the code is selecting a random test module to bind to the BP_GravitySphere actor from the "DynamicBinding" tutorial.

local testModules = {
    "Core.Tests.TestActions.BP_TestAction_01",
    "Core.Tests.TestActions.BP_TestAction_02",
    "Core.Tests.TestActions.BP_TestAction_03",
    "Core.Tests.TestActions.BP_TestAction_04"
}

function M:LeftMouseButton_Pressed()
    local World = self:GetWorld()
    local SpawnClass = self.SpawnClass
    local Transform = self.SpawnPointActor:GetTransform()
    local AlwaysSpawn = UE.ESpawnActorCollisionHandlingMethod.AlwaysSpawn
    -- World:SpawnActor(SpawnClass, Transform, AlwaysSpawn, self, self, "Tutorials.GravitySphereActor")
    local LuaModulePath = testModules[math.random(#testModules)]
    print(LuaModulePath)
    World:SpawnActor(SpawnClass, Transform, AlwaysSpawn, self, self, LuaModulePath):Run()
end

The Test modules are just a simple print:

function BP_TestAction_01:Run()
    local msg = [[
      Successfully Ran Test Action 01
    ]]
    print(msg)
end

The expected behavior is, each time Left Mouse is pressed, a random Module is selected, bound to the spawned actor and function "Run" is done.

This is not the case, in all cases, the Spawn Actor will be bound to the first module that was bound each time the mouse is clicked:

LogUnLua: Core.Tests.TestActions.BP_TestAction_04
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_03
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_03
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_01
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_02
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_02
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_03
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_03
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_03
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_04
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_02
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_01
LogUnLua:       Successfully Ran Test Action 04
    
LogUnLua: Core.Tests.TestActions.BP_TestAction_01
LogUnLua:       Successfully Ran Test Action 04
@jacobhinds
Copy link

Same issue for 2.2.4, UE 4.27. NewObject() created objects only use the first file dynamically bound to them.

@jozhn
Copy link
Contributor

jozhn commented Jan 24, 2024

You cannot bind different lua modules to one UClass, because UFunctions are stored in the UClass.
UnLua will only use the first binding, other bindings will be ignored.

If you really need to do this, try generated different classes from the SpawnClass dynamically and then bind different lua modules to them. See my reply in #658

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

No branches or pull requests

3 participants