Tencent / UnLua

A feature-rich, easy-learning and highly optimized Lua scripting plugin for UE.
Other
2.28k stars 619 forks source link

Running Lua code on the Construction Script #568

Open faseceroo opened 2 years ago

faseceroo commented 2 years ago

I'm having trouble executing Lua code in the Construction Script for objects that exist in the editor BEFORE pressing play.

This is a slider I have dropped in the level object

this is the code I need to run lua1

It doesn't work if I override the function and call it from blueprint lua2

Nor if I call it from lua directly lua3

in both cases something is wrong, maybe the BP components have not yet been created. I know I can call this function in BeginPlay but the Construction Script can be useful sometimes.

xuyanghuang-tencent commented 2 years ago

Currently UnLua only support overriding functions in a PIE environment. You can try the feature/editor branch, which will be released in version 2.4.0. It provides a function called RunInEditor within UnLuaInterface.

faseceroo commented 2 years ago

That's great, I think I'm gonna wait for version 2.4 then. I'll keep doing the constructors with BP nodes and else with Unlua. Thank you very much.

P.D: (as a side note please consider creating a discord channel or forum for Unlua, it is awesome).

faseceroo commented 1 year ago

Hello, my first impressions about 2.4 although I understand it is a pre-release.

This code works fine from the constructor, it is creating a dynamic material from the static mesh. I think I had to restart UE for it to take effect.

editor1

this doesn't seem to work calling it from the constructor, it is creating a dynamic material with a material variable (self.material) defined in the editor

editor2

editor3

Also I'm using LuaHelper extension in vscode and when I activate Run in Editor the breakpoints stop working when debugging with LuaPanda in that file.