Hey guys,
I’m currently working on a tool within Unreal Engine 4 that allows our designer to quickly place Actors inside our levels, and hook certain variables onto it.
Currently I am at the point of spawning the Actors inside the level, and all is going well. However, I want the Actor to spawn in front of the camera’s viewport to access it quickly, and not let the Actor spawn at lets say (0,0,0).
I have been working on this issue for quite some time now, and I’m new to C++. (Yes I have knowledge and experience in Blueprints and with the Editor itself).
//Init spawn location
FVector spawnLocation = FVector(0, 0, 0);
//Get viewport location
UWorld* world = GetWorld();
if (world != NULL)
{
auto viewLocations = world->ViewLocationsRenderedLastFrame;
if (viewLocations.Num() != 0)
{
//This works well. I get the exact location of the Editor Camera.
spawnLocation = viewLocations[0];
}
FLevelEditorViewportClient* ViewportClient = GEditor->LevelViewportClients[0];
FRotator Rotation = ViewportClient->GetViewRotation();
FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
Direction.Normalize();
spawnLocation += Direction * 600.0f;
//The code below all result in Rotation (0,0,0), no matter what angle I have tilted the Camera to.
UE_LOG(WaboLog, Warning, TEXT("ViewportClient %s"), *ViewportClient->LastEditorViewRotation.ToString());
UE_LOG(WaboLog, Warning, TEXT("Rotation %s"), *Rotation.ToString());
}
I’m really staring blanks right now. If somebody could point me into the right direction, that would be gladly appreciated!
Thanks in advance,
Wabo