Setting an actor's transform is failing

Hey folks,

I’m a bit of a n00b, so I’m sure that I am missing something simple. My problem is that, when I try to initialize an actor with a specific transform (or set it it using SetActorTransform() ), it seems to fail. For instance, if I do:

FTransform Transf; // do some stuff here
auto Actor = GetWorld()->SpawnActor<MyActorClass>( Transf.GetLocation(), Transf.Rotator() );
bool TransfSet = Actor->SetActorTransform(Transf, false);

If I check the transform immediately after SpawnActor(), I get identity. Same with checking right after SetActorTransform(). Similarly, TransfSet is false.

So, what might be the problem? Why might this fail? I tried googling around, and it seems that the only way this should fail is if I were to pass true for the bSweep parameter, and the object collides with something. That should not be applicable to my current case. So, what else might be going wrong?

Cheers,

You could check if your transform is messed up by doing …


SetActorRotation()
SetActorLocation()

… separately. Also, why not just set the location and rotation in the SpawnActor call?


GetWorld()->SpawnActor<AProjectile>(Location, Rotation, SpawnInfo);

Thanks. I tried all kinds of methods (setting the whole transform at once VS the location and rotation separately, using SpawnActor vs setting them after the actor is created). Nothing worked. No matter what I do, I get zero vectors when I later ask for the actor’s location or rotation (or its combined transform).

I have the same problem, did you find a solution?

I spawned 4 actors at different positions but they all end up like they do not have a transform, see screenshot.

I found out what was wrong in my code. My actor was missing a RootComponent, so I had to add one.

I added this in the constructor and it worked.



USceneComponent* SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
RootComponent = SceneComponent;


https://docs.unrealengine.com/en-us/Programming/Tutorials/Components/1