I got a custom viewport editor that I use in a custom asset. For some reason not all actors are showing in this viewport.
Here is video showing the issue.
Unreal (Custom Editor Viewport Not Properly Working) - YouTube
First you see I press play and the actors show up in Play mode.
Than I run the graph in editor and only the character shows up.
3rd I show the actors showing in there own viewport in there blueprint.
// Fill out your copyright notice in the Description page of Project Settings.
#include "FluidArchitectCoreEditorViewportModuleWidget.h"
/*------------------------------------------------------------------------------
Fluid Architect Core Editor : Scene Module (Preview Scene)
------------------------------------------------------------------------------*/
FFluidArchitectCoreEditorViewportModulePreviewScene::FFluidArchitectCoreEditorViewportModulePreviewScene():FPreviewScene()
{
// world setting
GetWorld()->GetWorldSettings()->NotifyBeginPlay();
GetWorld()->GetWorldSettings()->NotifyMatchStarted();
GetWorld()->GetWorldSettings()->SetActorHiddenInGame(false);
GetWorld()->bBegunPlay = true;
// set light options
// DirectionalLight->SetRelativeLocation(FVector(-1024.f, 1024.f, 2048.f));
// DirectionalLight->SetRelativeScale3D(FVector(15.f));
// SetLightBrightness(4.f);
// DirectionalLight->InvalidateLightingCache();
// DirectionalLight->RecreateRenderState_Concurrent();
// creae a sky sphere
// UStaticMeshComponent* SkyComp = NewObject<UStaticMeshComponent>();
// UStaticMesh * StaticMesh = LoadObject<UStaticMesh>(NULL, TEXT("/Engine/MapTemplates/Sky/SM_SkySphere.SM_SkySphere"), NULL, LOAD_None, NULL);
// SkyComp->SetStaticMesh(StaticMesh);
// UMaterial* SkyMaterial = LoadObject<UMaterial>(NULL, TEXT("/Engine/EditorMaterials/PersonaSky.PersonaSky"), NULL, LOAD_None, NULL);
// SkyComp->SetMaterial(0, SkyMaterial);
// const float SkySphereScale = 1000.f;
// const FTransform SkyTransform(FRotator(0, 0, 0), FVector(0, 0, 0), FVector(SkySphereScale));
// AddComponent(SkyComp, SkyTransform);
// now add floor
// UStaticMesh* FloorMesh = LoadObject<UStaticMesh>(NULL, TEXT("/Engine/EditorMeshes/EditorCube.EditorCube"), NULL, LOAD_None, NULL);
// UStaticMeshComponent* FloorComp = NewObject<UStaticMeshComponent>();
// FloorComp->SetStaticMesh(FloorMesh);
// AddComponent(FloorComp, FTransform::Identity);
// FloorComp->SetRelativeScale3D(FVector(3.f, 3.f, 1.f));
// UMaterial* Material = LoadObject<UMaterial>(NULL, TEXT("/Engine/EditorMaterials/PersonaFloorMat.PersonaFloorMat"), NULL, LOAD_None, NULL);
// FloorComp->SetMaterial(0, Material);
// FloorComp->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
// FloorComp->SetCollisionObjectType(ECC_WorldStatic);
}
/*------------------------------------------------------------------------------
Fluid Architect Core Editor : Scene Module (Viewport Client)
------------------------------------------------------------------------------*/
FFluidArchitectCoreEditorViewportModuleViewportClient::FFluidArchitectCoreEditorViewportModuleViewportClient(FFluidArchitectCoreEditorViewportModuleWidget* ViewportWidget,FEditorModeTools* InModeTools,FPreviewScene* InPreviewScene):FEditorViewportClient(InModeTools,InPreviewScene)
{
FEditorViewportClient(InModeTools,InPreviewScene);
SetRealtime(true);
ArchitectCorePreviewViewportWidget = ViewportWidget;
}
FFluidArchitectCoreEditorViewportModuleViewportClient::~FFluidArchitectCoreEditorViewportModuleViewportClient()
{
ArchitectCorePreviewViewportWidget = nullptr;
}
void FFluidArchitectCoreEditorViewportModuleViewportClient::Tick(float DeltaSeconds)
{
FEditorViewportClient::Tick(DeltaSeconds);
PreviewScene->GetWorld()->Tick(LEVELTICK_All, DeltaSeconds);
PreviewScene->GetWorld()->UpdateConstraintActors();
if (ArchitectCorePreviewViewportWidget == nullptr)
return;
if (ArchitectCorePreviewViewportWidget->Module->Type == FLUID_ARCHITECT_CORE_RUNTIME_VIEWPORT_MODULE_TYPE_2D)
SetViewportType(LVT_OrthoXY); // Top Down
else
SetViewportType(LVT_Perspective); // 3D
// Get Asset
const auto Asset = ArchitectCorePreviewViewportWidget->Asset;
if (Asset == nullptr)
return;
// Cal Viewport Init
if (!bDidInit)
Asset->OnViewportModuleInit(ArchitectCorePreviewViewportWidget->Module,PreviewScene->GetWorld());
bDidInit = true;
// Call Viewport Tick
Asset->OnViewportModuleTick(ArchitectCorePreviewViewportWidget->Module,PreviewScene->GetWorld());
}
void FFluidArchitectCoreEditorViewportModuleViewportClient::Draw(FViewport* InViewport, FCanvas* Canvas)
{
// Draw (With Black Background)
FEditorViewportClient::Draw(InViewport,Canvas);
// Get Asset
const auto Asset = ArchitectCorePreviewViewportWidget->Asset;
if (Asset == nullptr)
return;
// Call Viewport Draw
Asset->OnViewportModuleDraw(ArchitectCorePreviewViewportWidget->Module,PreviewScene->GetWorld(),InViewport,Canvas);
}
/*------------------------------------------------------------------------------
Fluid Architect Core Editor : Scene Module (Widget)
------------------------------------------------------------------------------*/
void FFluidArchitectCoreEditorViewportModuleWidget::Construct(const FArguments& InArgs)
{
SEditorViewport::Construct(SEditorViewport::FArguments());
}
FFluidArchitectCoreEditorViewportModuleWidget::FFluidArchitectCoreEditorViewportModuleWidget()
{
}
FFluidArchitectCoreEditorViewportModuleWidget::~FFluidArchitectCoreEditorViewportModuleWidget()
{
ViewportClient = nullptr;
}
TSharedRef<class SEditorViewport> FFluidArchitectCoreEditorViewportModuleWidget::GetViewportWidget()
{
return SharedThis(this);
}
TSharedPtr<FExtender> FFluidArchitectCoreEditorViewportModuleWidget::GetExtenders() const
{
TSharedPtr<FExtender> Result(MakeShareable(new FExtender));
return Result;
}
void FFluidArchitectCoreEditorViewportModuleWidget::OnFloatingButtonClicked()
{
}
TSharedRef<FEditorViewportClient> FFluidArchitectCoreEditorViewportModuleWidget::MakeEditorViewportClient()
{
PreviewScene = MakeShareable(new FFluidArchitectCoreEditorViewportModulePreviewScene());
ViewportClient = new FFluidArchitectCoreEditorViewportModuleViewportClient(this,nullptr, PreviewScene.Get());
return (MakeShareable(ViewportClient));
}
TSharedPtr<SWidget> FFluidArchitectCoreEditorViewportModuleWidget::MakeViewportToolbar()
{
auto Toolbar = SNew(SCommonEditorViewportToolbarBase, SharedThis(this));
Toolbar.Get().SetVisibility(EVisibility::Hidden);
return Toolbar;
}
UWorld* FFluidArchitectCoreEditorViewportModuleWidget::HelperGetWorld() const
{
return ViewportClient->GetWorld();
}
I spawn the actors like so
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
auto Actor = NodeGraphModuleRunState->MainWorld->SpawnActor<AActor>(ActorClass, FVector::ZeroVector, FRotator::ZeroRotator, SpawnParams);