Draw Abstract Instances in Editor
Hey I found a new way to draw the Abstract Instances in the Editor. Since the provided code is broken in AFGBuildable.
Also this way doesn't need to edit the Header of CSS:
AccessTransformers.ini:
.h:
.cpp:
[AccessTransformers]
Friend = (Class="AFGBuildable", FriendClass="UKBFLEditorSubsystem")
[AccessTransformers]
Friend = (Class="AFGBuildable", FriendClass="UKBFLEditorSubsystem")
#pragma once
#include "CoreMinimal.h"
#include "EditorSubsystem.h"
#include "KBFLEditorSubsystem.generated.h"
UCLASS()
class KBFL_API UKBFLEditorSubsystem : public UEditorSubsystem {
GENERATED_BODY()
public:
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override { Super::Deinitialize(); };
private:
static void OnWorldPreActorTick(UWorld* World, ELevelTick TickType, float DeltaSeconds);
};
#pragma once
#include "CoreMinimal.h"
#include "EditorSubsystem.h"
#include "KBFLEditorSubsystem.generated.h"
UCLASS()
class KBFL_API UKBFLEditorSubsystem : public UEditorSubsystem {
GENERATED_BODY()
public:
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override { Super::Deinitialize(); };
private:
static void OnWorldPreActorTick(UWorld* World, ELevelTick TickType, float DeltaSeconds);
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Editor/KBFLEditorSubsystem.h"
#include "AbstractInstanceManager.h"
#include "Buildables/FGBuildable.h"
class AFGBuildable;
void UKBFLEditorSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
FWorldDelegates::OnWorldPreActorTick.AddStatic(&UKBFLEditorSubsystem::OnWorldPreActorTick);
}
void UKBFLEditorSubsystem::OnWorldPreActorTick(UWorld* World, ELevelTick TickType, float DeltaSeconds)
{
if (World->WorldType == EWorldType::EditorPreview)
{
for (FConstLevelIterator LevelIt = World->GetLevelIterator(); LevelIt; ++LevelIt)
{
for (AActor* actor : (*LevelIt)->Actors)
{
if (AFGBuildable* Buildable = Cast<AFGBuildable>(actor))
{
if (Buildable->mCanContainLightweightInstances && IsValid(Buildable->mInstanceDataCDO) && Buildable->mInstanceHandles.IsEmpty())
{
for (FInstanceData InstanceData : Buildable->mInstanceDataCDO->GetInstanceData())
{
if (IsValid(InstanceData.StaticMesh) && !InstanceData.OverridenMaterials.Contains(nullptr))
{
FInstanceHandle* Handle;
AAbstractInstanceManager::SetInstanceFromDataStatic(Buildable, FTransform(), InstanceData, Handle, false);
Buildable->mInstanceHandles.Add(Handle);
}
}
}
}
}
}
}
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "Editor/KBFLEditorSubsystem.h"
#include "AbstractInstanceManager.h"
#include "Buildables/FGBuildable.h"
class AFGBuildable;
void UKBFLEditorSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
FWorldDelegates::OnWorldPreActorTick.AddStatic(&UKBFLEditorSubsystem::OnWorldPreActorTick);
}
void UKBFLEditorSubsystem::OnWorldPreActorTick(UWorld* World, ELevelTick TickType, float DeltaSeconds)
{
if (World->WorldType == EWorldType::EditorPreview)
{
for (FConstLevelIterator LevelIt = World->GetLevelIterator(); LevelIt; ++LevelIt)
{
for (AActor* actor : (*LevelIt)->Actors)
{
if (AFGBuildable* Buildable = Cast<AFGBuildable>(actor))
{
if (Buildable->mCanContainLightweightInstances && IsValid(Buildable->mInstanceDataCDO) && Buildable->mInstanceHandles.IsEmpty())
{
for (FInstanceData InstanceData : Buildable->mInstanceDataCDO->GetInstanceData())
{
if (IsValid(InstanceData.StaticMesh) && !InstanceData.OverridenMaterials.Contains(nullptr))
{
FInstanceHandle* Handle;
AAbstractInstanceManager::SetInstanceFromDataStatic(Buildable, FTransform(), InstanceData, Handle, false);
Buildable->mInstanceHandles.Add(Handle);
}
}
}
}
}
}
}
}
2 Replies
@Rex https://github.com/satisfactorymodding/SatisfactoryModLoader/pull/268/files I see this PR I think thats a better way also because it doesn't need any header edit's
I need to revise that PR because it's currently a mess