Hi,
I’m currently trying to instantiate a separate world, and add an USceneCaptureComponent2D to it.
I try to create the new world like so:
UPackage *WorldPackage = FindPackage(nullptr, *LevelName);
if (WorldPackage == nullptr)
{
WorldPackage = LoadPackage(nullptr, *LevelName, LOAD_None);
}
UWorld *NewWorld = UWorld::FindWorldInPackage(WorldPackage);
FWorldContext &WorldContext = GEngine->CreateNewWorldContext(EWorldType::None); // ?
WorldContext.SetCurrentWorld(NewWorld);
NewWorld->WorldType = WorldContext.WorldType;
NewWorld->SetGameInstance(WorldContext.OwningGameInstance);
NewWorld->InitWorld();
FURL URL;
NewWorld->InitializeActorsForPlay(URL);
NewWorld->BeginPlay();
Iterating over the Actors in the newly created world yields that all the actors of the level to load are present.
The actor that holds the capture component also gets ticked as it should.
The problem that i encounter is, that bCaptureEveryFrame
does not result in the capture components UpdateContent()
to be called.
This is because the capture components MarkedForEndOfFrameUpdateState
is wrong.
When calling UpdateContent()
manually in my actors Tick()
, it gets rendered, but the render target is still black.
any hints and
Update
I noticed that void USceneCaptureComponent2D::UpdateDeferredCaptures( FSceneInterface* Scene )
is not called for NewWorld
, since there is no window rendered for it.
Calling UpdateDeferredCaptures()
explicitly in my actor’s Tick()
function, results in the scene captures in NewWorld
for which bCaptureEveryFrame = true
being rendered.
However, the corresponding render targets are still black.
void AMyActor::Tick(float DeltaTime)
{
// ...
// Improvised code to force update of capture components...
NewWorld->SendAllEndOfFrameUpdates();
USceneCaptureComponent2D::UpdateDeferredCaptures(NewWorld->Scene);
}
Any hints or ideas are appreciated.