Some more progress.
I had a look at events to see how you would want to use them as a scripter.
One way could be to just declare a function with the event name and you are good to go, the other method would include subscribing to any event with a listener.
The fully dynamic solution would require the scripter to know the internals of the events, e.g. the BP event Hit is called via delegate “OnActorHit”.
I decided to test the hardcoded version with a simple “EventHit” function that is called whenever the Actor triggers the event. So the Lua code will look like this:
function EventHit(hitActor, otherActor, normalImpulse, hitResult)
print("Lua function EventHit()")
print("Hit Actor: " .. hitActor:GetName())
print("Other Actor: " .. otherActor:GetName())
print("normalImpulse: " .. normalImpulse:ToString())
print("hitResult.BoneName: " .. hitResult.BoneName)
print("hitResult.Location: " .. hitResult.Location:ToString())
end
Next I wanted a workflow that is more “programmer” like than visual coding with BP but still not as complex as C++. I really like the tools from JetBrains so I choose to use IntelliJ as the base.
IntelliJ has no builtin support for Lua but the Lua plugin seems good.
I like the simple way to refresh and start VS from the main menu so I added a similar function for Lua:
The Refresh action will make a very basic code completion file for the Lua plugin. Setting up the complete IDEA folder structure could maybe be a next step.
The Open action will start a predefined installation of IntelliJ pointing to the project.
When a Lua project gets bigger and more complex you need a way to structure it. So my next investigation was into Lua modules, both your own but also ready made packages.
As all Lua code must be self contained in an asset the modules needs to be handled the same way.
The Engine script plugin uses the Blueprint magic to handle this but as I’m not yet an engine magician I choose to simply use the component for the modules.
The downside is that the Actor BP needs a manual compile to load the Lua modules, I have not found a way to trigger the BP as dirty from inside the Actor.
So after checking a script component as a Lua module:
Now you can use the standard Lua function to include a Lua module:
require("ActorUtils")
print("Just loaded a module")
MeshUtils.SetMeshColor(MyStaticMesh, ue.Color.MakeRandomColor())
In the Lua module (ActorsUtilities.lua):
MeshUtils = {}
function MeshUtils.SetMeshColor(mesh, color)
print("Setting Color")
local dynamicMaterial = mesh:CreateDynamicMaterialInstance(0)
local linColor = ue.LinearColor(color)
dynamicMaterial:SetVectorParameterValue("ColorScreen", linColor)
end
Finally to summarize the currently SWIG wrapped Classes/Functions:
Actor, ActorComponent, Color, DrawDebug*(), FileHelper, GameplayStatics, HitResult, LinearColor, MaterialInstance, MaterialInstanceDynamic,
Matrix, MeshComponent, Object, Paths, PrimitiveComponent, Quat, Rotator, SceneComponent, StaticMeshComponent, Transform, Vector, Vector2D, Vector4, World
Strings and numbers are converted from FString, FName, uint32, float, etc to use standard Lua strings and number types.