Here is the code im using to spawn a scene capture actor. I want each scene capture to render to a texture which I can use in code for calculations.
#include "SensorMountedVehicle.h"
#include "Components/SceneCaptureComponent2D.h"
#include "Engine/SceneCapture2D.h"
#include "Blueprint/UserWidget.h"
#include "Blueprint/UserWidget.h"
#include "Engine/World.h"
#include "Engine/EngineTypes.h"
#include "TextureResource.h"
#include "Engine/TextureRenderTarget2D.h"
#include "InputCoreTypes.h"
#include "Styling/SlateBrush.h"
#include "ConstructorHelpers.h"
#include "TextFormatter.h"
void ASensorMountedVehicle::BeginPlay()
{
Super::BeginPlay();
UE_LOG(LogTemp, Error, TEXT("NumSensor: %d"), sensors.Num());
sensorRenderTargets.Reset();
for (auto& sensor : sensors) {
auto s = sensor.GetDefaultObject();
UE_LOG(LogTemp, Error, TEXT("%f %f %f %f, %f %f %f, %f %f %f, %d"),
s->rot_x, s->rot_y, s->rot_z, s->rot_w, s->scale_x, s->scale_y, s->scale_z,
s->trans_x, s->trans_y, s->trans_z, (int)s->type.GetValue()
);
ASceneCapture2D *sceneCaptureActor = (class ASceneCapture2D *)GetWorld()->SpawnActor<ASceneCapture2D>(ASceneCapture2D::StaticClass());
if (sceneCaptureActor) {
sceneCaptureActor->AttachToComponent(this->GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
FTransform trans = FTransform(
FQuat(s->rot_x, s->rot_y, s->rot_z, s->rot_w),
FVector(s->scale_x, s->scale_y, s->scale_z),
FVector(s->trans_x, s->trans_y, s->trans_z)
);
sceneCaptureActor->AddActorWorldTransform(trans);
auto *captureComponent = sceneCaptureActor->GetCaptureComponent2D();
captureComponent->FOVAngle = 90.0;
captureComponent->ProjectionType = ECameraProjectionMode::Perspective;
UTextureRenderTarget2D *renderTarget2D = NewObject<UTextureRenderTarget2D>();
sensorRenderTargets.Add(captureComponent->TextureTarget);
captureComponent->TextureTarget = renderTarget2D;
//sceneCaptureActor->bCaptureOnMovement = false;
//sceneCaptureActor->bCaptureEveryFrame = false;
//sceneCaptureActor->MaxViewDistanceO.verride = -1.0f;
captureComponent->bAutoActivate = true;
captureComponent->DetailMode = EDetailMode::DM_High;
switch (sensor.GetDefaultObject()->type) {
case SensorType::RADAR:
UE_LOG(LogTemp, Error, TEXT("Found Radar"));
captureComponent->CaptureSource = SCS_SceneColorHDR;
break;
case SensorType::LIDAR:
UE_LOG(LogTemp, Error, TEXT("Found Lidar"));
captureComponent->CaptureSource = SCS_SceneDepth;
break;
default:
UE_LOG(LogTemp, Error, TEXT("Sensor config has unknown type"));
break;
}
//sceneCaptureActor->RegisterComponent();
mountedSensors.Add(sceneCaptureActor);
}
else {
UE_LOG(LogTemp, Error, TEXT("SceneCapture loaded is null"));
}
}
}
ASensorMountedVehicle::~ASensorMountedVehicle()
{
for (auto& sensor : mountedSensors) {
delete sensor;
}
}
When running, this causes the entire editor to crash with the following output
Assertion failed: UnscaledViewRect.Width() > 0 [File:D:\Build\++UE4+Release-4.18+Compile\Sync\Engine\Source\Runtime\Engine\Private\SceneView.cpp] [Line: 646]
UE4Editor_Core!FDebug::AssertFailed() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:414]
UE4Editor_Engine!FSceneView::FSceneView() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\sceneview.cpp:647]
UE4Editor_Renderer!CreateSceneRendererForSceneCapture() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\renderer\private\scenecapturerendering.cpp:421]
UE4Editor_Renderer!CreateSceneRendererForSceneCapture() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\renderer\private\scenecapturerendering.cpp:537]
UE4Editor_Renderer!FScene::UpdateSceneCaptureContents() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\renderer\private\scenecapturerendering.cpp:582]
UE4Editor_Engine!USceneCaptureComponent::UpdateDeferredCaptures() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\components\scenecapturecomponent.cpp:408]
UE4Editor_Renderer!FRendererModule::BeginRenderingViewFamily() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\renderer\private\scenerendering.cpp:2257]
UE4Editor_Engine!UGameViewportClient::Draw() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\gameviewportclient.cpp:1278]
UE4Editor_Engine!FViewport::Draw() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\engine\private\unrealclient.cpp:1213]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4+release-4.18+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1862]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.18+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:396]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3296]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\launch.cpp:166]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:134]
UE4Editor!WinMain() [d:\build\++ue4+release-4.18+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:210]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253]
kernel32
ntdll
Not sure whats happening