Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions UE4SS/src/LuaType/LuaUWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ namespace RC::LuaType
std::string error_overload_not_found{R"(
No overload found for function 'SpawnActor'.
Overloads:
#1: SpawnActor(UClass Class, table Location, table Rotation))"};
#1: SpawnActor(UClass Class, table Location, table Rotation)
#2: SpawnActor(UClass Class, table Location, table Rotation, table Scale))"};

if (!lua.is_userdata())
{
Expand Down Expand Up @@ -136,10 +137,41 @@ No overload found for function 'SpawnActor'.
lua.throw_error(error_overload_not_found);
}

auto* actor = lua_object.get_remote_cpp_object()->SpawnActor(actor_class.get_remote_cpp_object(), &location, &rotation);
LuaType::AActor::construct(lua, actor);
// Check if we have a scale parameter
if (lua.is_table())
{
// Handle scale parameter
Unreal::FVector scale{1.0f, 1.0f, 1.0f};
lua.for_each_in_table([&](const LuaMadeSimple::LuaTableReference& table) {
if (table.key.is_string() && table.key.get_string() == "X" && table.value.is_number())
{
scale.SetX(table.value.get_number());
}

return 1;
if (table.key.is_string() && table.key.get_string() == "Y" && table.value.is_number())
{
scale.SetY(table.value.get_number());
}

if (table.key.is_string() && table.key.get_string() == "Z" && table.value.is_number())
{
scale.SetZ(table.value.get_number());
}
return false;
});

Unreal::FTransform transform{rotation, location, scale};
auto* actor = lua_object.get_remote_cpp_object()->SpawnActor(actor_class.get_remote_cpp_object(), &transform);
LuaType::AActor::construct(lua, actor);
return 1;
}
else
{
// Original behavior without scale
auto* actor = lua_object.get_remote_cpp_object()->SpawnActor(actor_class.get_remote_cpp_object(), &location, &rotation);
LuaType::AActor::construct(lua, actor);
return 1;
}
});

if constexpr (is_final == LuaMadeSimple::Type::IsFinal::Yes)
Expand Down
5 changes: 5 additions & 0 deletions docs/lua-api/classes/uworld.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
This function uses `UGameplayStatics:BeginDeferredActorSpawnFromClass` and `UGameplayStatics:FinishSpawningActor` to spawn an actor.
- **Return type:** `AActor`
- **Returns:** Spawned actor object or an invalid object.

### SpawnActor(UClass ActorClass, FVector Location, FRotator Rotation, FVector Scale)
This function uses `UGameplayStatics:BeginDeferredActorSpawnFromClass` and `UGameplayStatics:FinishSpawningActor` to spawn an actor.
- **Return type:** `AActor`
- **Returns:** Spawned actor object or an invalid object.
Loading