Skip to content

fix: pass scale to UEPseudo UWorld::SpawnActor #864

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

massclown
Copy link
Contributor

Description
Currently in UE4SS it is not easy to spawn scaled actors from Lua, and for some actors setting scale after spawning may not work (animated characters, etc.).

In Re-UE4SS/UEPseudo/blob/main/src/World.cpp, the first implementation of UWorld::SpawnActor hardcodes the scale to 1.0:

    AActor* UWorld::SpawnActor(UClass* InClass, FVector const* Location, FRotator const* Rotation)
    {
        Unreal::FTransform Transform{
                Rotation ? FQuat(*Rotation) : FQuat(),
                Location ? *Location : FVector(),
                {1.0f, 1.0f, 1.0f},
...

and the second AActor* UWorld::SpawnActor(UClass* Class, FTransform const* Transform) needs an FTransform which is not passed through Lua currently.

To follow the style of the existing API, we add another Lua overload, that also accepts one more, the fourth table parameter, a FVector-like table of scale:

SpawnActor(UClass ActorClass, FVector Location, FRotator Rotation, FVector Scale)

and constructs an FTransform to call the relevant second implementation from UEPseudo.

The original SpawnActor(UClass ActorClass, FVector Location, FRotator Rotation) should still work as before.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?
Built locally and tested manually.

@UE4SS
Copy link
Collaborator

UE4SS commented Apr 26, 2025

This breaks from UEs API.
There is no SpawnActor overload in UE that takes scale directly as a parameter.

An alternative is to expose the overload that takes FTransform to Lua.
What do you think @narknon ?

@UE4SS UE4SS requested a review from narknon April 26, 2025 05:52
@narknon
Copy link
Collaborator

narknon commented Apr 27, 2025

This breaks from UEs API. There is no SpawnActor overload in UE that takes scale directly as a parameter.

An alternative is to expose the overload that takes FTransform to Lua. What do you think @narknon ?

I haven't reviewed the code but it seems relatively benign if we could have an extra overload that just has scale without breaking the others and with still allowing us to have an FTransform version. I guess it's possible it could cause issues in the future if UE does another overload that somehow won't work with our overloads, but that seems unlikely.

@massclown
Copy link
Contributor Author

I can take a stab at implementing the FTransform API with a table of tables like:

SpawnActor(UClass Class, table Transform {Location={X,Y,Z}, Rotation={Pitch,Yaw,Roll}, Scale={X,Y,Z}}))"};

Would that be better?

@UE4SS
Copy link
Collaborator

UE4SS commented Apr 27, 2025

I can take a stab at implementing the FTransform API with a table of tables like:

SpawnActor(UClass Class, table Transform {Location={X,Y,Z}, Rotation={Pitch,Yaw,Roll}, Scale={X,Y,Z}}))"};

Would that be better?

I would prefer it, but I'm not gonna block the original idea that just adds the Scale3D param, up to you to decide now.

If you do go ahead with the FTransform overload, here are a few problems:
The rotation for FTransform is an FQuat not an FRotator.
Your order is also incorrect, which I think you should correct even if it only affects the docs, I don't recall if we usually accept only named or also unnamed tables for vectors etc, please check and conform to what we currently do.
The correct order is Rotation, Translation, Scale3D.

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.

3 participants