You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3050029 on 2016/07/14 by Ben.Cosh This modifies the blueprint instrumented compilation chain so only the the blueprint you compile and all dependencies are instrumented and the profiler is notified rather than waiting for event data. #Jira UE-32063 - The blueprint profiler doesn't display any stats in the execution graph if no instance is placed in the current level. #Proj BlueprintProfiler, Kismet, UnrelEd - This also improves the execution graph UI, notifying the user that no instances are available to display data from. Change 3101549 on 2016/08/25 by Maciej.Mroz BP nativization: fixed FEmitDefaultValueHelper::HandleInstancedSubobject https://udn.unrealengine.com/questions/308800/nativized-blueprints-newobject-call-uses-incorrect.html Change 3101811 on 2016/08/25 by Ryan.Rauschkolb BP Profiler: Fixed stack overflow crash when compiling blueprints with nested macros #jira UE-34503 Change 3102478 on 2016/08/26 by Maciej.Mroz #jira UE-35135 - Odin compiles with errors when using Blueprint nativization BP Nativization: - improved native cast - improved bool handling Change 3102944 on 2016/08/26 by Phillip.Kavan [UE-33017] Don't include transient properties when generating property lists at cook time for optimized runtime Blueprint component instancing. Also ensure that deprecated properties are serialized during load/instancing at runtime. change summary: - modified FBlueprintComponentInstanceDataLoader to append 'PPF_UseDeprecatedProperties' to the FArchive port flags. - modified FBlueprintComponentInstanceDataWriter to append both 'PPF_Duplicate' and 'PPF_UseDeprecatedProperties" to the FArchive port flags (to ensure consistency w/ the instancing side). - switched the RecursivePropertyGatherLambda helper to a static class method instead - modified the RecursivePropertyGather utility method to exclude transient properties. notes: - the primary cause of UE-33017 was that UBodySetup can "share" the ShapeBodySetup object across all instances, but the shared object is not owned by the CDO, it's owned by the archetype. this caused the archetype to differ from the CDO, which caused us to emit the transient property at cook time. thsi threw off the serialization offset between read/write FArchive passes at runtime. since transient properties are not serialized as part of the template, there's no need to include them in the generated delta property list, so as a fix, i'm just excluding them altogether. #jira UE-33017 Change 3103692 on 2016/08/27 by Mike.Beach Merging //UE4/Dev-Main to Dev-Blueprints (//UE4/Dev-Blueprints) Change 3104266 on 2016/08/29 by Ben.Marsh Add test script to native assets for QAGame. Change 3104399 on 2016/08/29 by Ben.Marsh Fix missing property warning in build script. Change3104419on 2016/08/29 by Maciej.Mroz #jira UE-35135 Odin compiles with errors when using Blueprint nativization - Reduced number of DynamicCLass instance dependencies - Fixed UDS default values dependencies - Improved WeakObjPtr handling - Improved const parameters handling Change 3104474 on 2016/08/29 by Ryan.Rauschkolb BP Profiler: Fixed issue where collapsed nodes that share a name with a parent class collapsed node can cause a stack overflow #jira UE-35245 Change 3105605 on 2016/08/30 by Maciej.Mroz Temp change: CIS Test Change 3105738 on 2016/08/30 by Maciej.Mroz UAT, CIS: testing NoRecompileUAT switch. Change 3105800 on 2016/08/30 by Maciej.Mroz UAT, CIS, Nativization: - reverted NoRecompileUAT switch. - testing nativization with -nocompileeditor flag and without -compile flag Change 3106162 on 2016/08/30 by Maciej.Mroz UAT, CIS, Nativization: -NoSubmit flag added. Otherwise UAT files are singed (when they are used by other process). It causes an error. - Ugly hack removed. Change 3106261 on 2016/08/30 by Phillip.Kavan [UE-34705] Gracefully handle tunnel node entry exec pins that aren't internally linked during BP profiler tunnel boundary mapping. change summary: - added FBlueprintFunctionContext::GetTunnelBoundaryNode() (uncheckedl variant). - moved FBlueprintFunctionContext::GetTunnelBoundaryNodeChecked() impl into GetTunnelBoundaryNode(). - re-implemented FBlueprintFunctionContext::GetTunnelBoundaryNodeChecked() to call GetTunnelBoundaryNode() and then assert on the result. - changed the FBlueprintTunnelInstanceContext::GetTunnelBoundaryNodeChecked() impl to override GetTunnelBoundaryNode() instead. - modified FBlueprintFunctionContext::MapTunnelBoundary() to only process the entry case if the TunnelBoundaryNode result is valid. this way we simply skip tunnel boundary mapping if an entry path was not previously mapped (rather than assert). #jira UE-34705 Change 3106478 on 2016/08/30 by Ben.Marsh Include *.uasset files on builders running the NativizeAssets job. Change 3107514 on 2016/08/31 by Ben.Cosh This set of changes is the result of a full pass on the blueprint profiler heat interface to try and bring them into a usable state. #Jira UE-33465 - Stat heat colors and heat wire traces need a quick pass to ensure they are working as expected. #Jira UE-33309 - FlipFlop node breaks hottest path wire heatmap #Jira UE-33650 - Blueprint heatwire effects do not work when touching user macros #Jira UE-33706 - BP Profiler - Macro instances not colored or reporting time #Jira UE-33701 - BP Profiler: Hottest path wire heatmap doesn't appear to be working #Jira UE-33083 - BP Profiler - (Exclusive) pure node heatmap missing from some nodes #Jira UE-34855 - BP Profiler - Update heatmap coloration when switching between Default/Custom thresholds #Jira UE-32218 - BP Profiler: Clear "inclusive" time entries from "avg. time" row. #Proj GraphEditor, Kismet, BlueprintProfiler, Change 3108268 on 2016/08/31 by Ben.Cosh Minor change from profiler review sessions to move macro timing to average stats. #Jira UE-33706 - BP Profiler - Macro instances not colored or reporting time #Proj Kismet Change 3108991 on 2016/08/31 by Maciej.Mroz UAT, CIS, Nativization: Test separate cooking and compiling Change 3110097 on 2016/09/01 by Ben.Cosh Minor update to the blueprint profiler mapping functionality to ignore disabled nodes and a fix for the max timing white glow bug. #Jira UE-35377 - Blueprint macros highlighting white in profiler #Jira UE-34973 - Remove Ghost Nodes #Proj Kismet, BlueprintProfiler Change 3114553 on 2016/09/06 by Dan.Oconnor Support for TMap/TSet in blueprint variable editor panel #jira UE-2114 Change 3116367 on 2016/09/07 by Dan.Oconnor Fixed Function/Macro inputs/outputs list (had become cramped with my last change) + misc. fixes for new container types, fixes uninitialized members in FTerminalType #jira UE-2114, UE-35676 Change 3116663 on 2016/09/07 by Dan.Oconnor Fix for array functions showing up with TSet and TMap pins #jira UE-2114 Change 3118259 on 2016/09/08 by Ryan.Rauschkolb BP Profiler: Fixed Assert when profiling parent/child Blueprint #jira UE-35487 Change3119023on 2016/09/09 by Maciej.Mroz Manually integrated (from Odin branch) recent changes related to BP and nativization: 3115713 UE-35448 3117590 UE-35697 3117742 ODIN-577 Change 3119058 on 2016/09/09 by Maciej.Mroz #jira UE-32841 GitHub 2574 : fix typos #2574 https://github.com/EpicGames/UnrealEngine/pull/2574 Renamed function CustomNativeInitilize to InitializeNativeClassData and made it private. Change 3119302 on 2016/09/09 by Maciej.Mroz #jira UE-35584 Orion - nativized server crashes Global variable for WITH_PERFCOUNTERS definition in UEBuildConfiguration. Previously the same header could be compiled with the WITH_PERFCOUNTERS flag enadles and disabled (during a single compilation) . Change 3119502 on 2016/09/09 by Mike.Beach When building a deterministic UUID for latent nodes, we now use expanded nodes' origin (node) to avoid collisions (latent node in macros, etc.) #jira UE-35609 Change 3119517 on 2016/09/09 by Ryan.Rauschkolb Added blueprint editor settings option to display unique names for blueprint nodes Change 3119602 on 2016/09/09 by Maciej.Mroz #jira UEBP-214 Implement Solution for Nativized AnimBlueprints Size Reduction Added stats about nativized AnimBP Mechanism to exlcude reducible AnimBP Editor config option:[BlueprintNativizationSettings] bNativizeAnimBPOnlyWhenNonReducibleFuncitons=false Change 3119615 on 2016/09/09 by Maciej.Mroz Missing change (should be part of cl#3119602) Change 3119619 on 2016/09/09 by Maciej.Mroz #jira UEBP-214 Implement Solution for Nativized AnimBlueprints Size Reduction Excluding all AnimBP from Orion nativization. Change 3120752 on 2016/09/12 by Maciej.Mroz #jira UE-35051 [CrashReport] UE4Editor_BlueprintNativeCodeGen!FBlueprintNativeCodeGenModule::GenerateSingleAsset() Removed unnecessary ensure Change3121354on 2016/09/12 by Dan.Oconnor Fixed variable type width, required for TMap's extra combobox. Change 3121626 on 2016/09/12 by Phillip.Kavan [UE-35456] Fix crash on right-click in components tree view after copying one or more BSP actors to clipboard. Note: This applies to the components tree view in both the Blueprint editor and the Level editor's Actor details panel. change summary: - modified FComponentObjectTextFactory::CanCreateClass() to exclude Actor/Component subtypes that are not Blueprint-compatible (e.g. ABrush). #jira UE-35456 Change 3122712 on 2016/09/13 by Maciej.Mroz #jira UE-35714 [CrashReport] UE4Editor_BlueprintGraph!UK2Node_CallArrayFunction::GetArrayPins() [k2node_callarrayfunction.cpp:141] Replaced "check" with "ensure". Change 3124398 on 2016/09/14 by Maciej.Mroz More strict BP validation in UBlueprintThumbnailRenderer::Draw #jira UE-35705 Change 3124405 on 2016/09/14 by Maciej.Mroz #jira UE-35110 Packaged project crashes when playing sound from blueprint library with enum input after nativizing blueprints Function Libraries are properly added to dependencies list while nativization. Change 3124667 on 2016/09/14 by Maciej.Mroz #jira UE-35262 Incompatible pins give generate warning, when error is necessary. Fixed incompatible pins validation. Change 3125245 on 2016/09/14 by Phillip.Kavan [UE-33674] Fix missing stats for the ForEachElementInEnum node type in the Blueprint profiler tree view. change summary: - modified FScriptEventPlayback::Process() to not allow intermediate node exit pins to pollute the current trace path - modified FBlueprintFunctionContext::DetermineGraphNodeCharacteristics() to handle the UK2Node_ForEachElementInEnum type as a special case and account for extra loop iterations in the sample frequency computed at mapping time - exported UK2Node_ForEachElementInEnum::InsideLoopPinName and EnumOutputPinName string constants #jira UE-33674 Change 3126211 on 2016/09/15 by Maciej.Mroz #jira UE-36016 Struct pin can be connected to Object pin without error Change 3126393 on 2016/09/15 by Maciej.Mroz #jira UE-35936 Replace "check" by "ensure". Change 3126623 on 2016/09/15 by Maciej.Mroz #jira UE-35816 User defined struct array resets to defaults in blueprint after updating the struct STRUCT_SerializeFromMismatchedTag is not necessary to serialize structure when guids match. Anyway STRUCT_SerializeFromMismatchedTag sholud precede SerializeFromMismatchedTag(). Change 3127288 on 2016/09/15 by Mike.Beach Making the script VM overhead and native time stats threadsafe (to account for threaded anim Blueprints in Orion). Change 3127375 on 2016/09/15 by Mike.Beach Making sure Blueprint classes inherit the super's ClassConfigName properly (inherit the ID instead of the filename). Change 3127381 on 2016/09/15 by Mike.Beach Removing an overzealous ensure that certain users were hitting when a loading array property wasn't fully filled out yet (confirmed that it was populated with the proper objects by the end of the load). Change 3127476 on 2016/09/15 by Dan.Oconnor Build fix #jira UE-36073 Change 3128335 on 2016/09/16 by Maciej.Mroz #jira UE-36075 Odin: BP_DefaultHand and BigBotCharacter blueprints fail to compile Fixed broken BP assets. Change 3128589 on 2016/09/16 by Mike.Beach Fixing a static analysis CIS warning (duplicated condition). Change 3128630 on 2016/09/16 by Dan.Oconnor Re-fix with engine version set Change 3129338 on 2016/09/16 by Dan.Oconnor =FScriptSet/FScriptSetHelper fleshed out (Add, Remove, and Find implemented) +SetParam implemented for marking up sets for primitive Set functions (to be checked in once completed as BlueprintSetLibrary) #jira UE-2114 [CL 3131171 by Mike Beach in Main branch]
565 lines
18 KiB
C++
565 lines
18 KiB
C++
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "HotReloadPrivatePCH.h"
|
|
#include "HotReloadClassReinstancer.h"
|
|
|
|
#if WITH_ENGINE
|
|
#include "Engine/BlueprintGeneratedClass.h"
|
|
#include "Layers/ILayers.h"
|
|
#include "BlueprintEditor.h"
|
|
#include "Kismet2/CompilerResultsLog.h"
|
|
|
|
void FHotReloadClassReinstancer::SetupNewClassReinstancing(UClass* InNewClass, UClass* InOldClass)
|
|
{
|
|
// Set base class members to valid values
|
|
ClassToReinstance = InNewClass;
|
|
DuplicatedClass = InOldClass;
|
|
OriginalCDO = InOldClass->GetDefaultObject();
|
|
bHasReinstanced = false;
|
|
bSkipGarbageCollection = false;
|
|
bNeedsReinstancing = true;
|
|
NewClass = InNewClass;
|
|
|
|
// Collect the original CDO property values
|
|
SerializeCDOProperties(InOldClass->GetDefaultObject(), OriginalCDOProperties);
|
|
// Collect the property values of the new CDO
|
|
SerializeCDOProperties(InNewClass->GetDefaultObject(), ReconstructedCDOProperties);
|
|
|
|
SaveClassFieldMapping(InOldClass);
|
|
|
|
ObjectsThatShouldUseOldStuff.Add(InOldClass); //CDO of REINST_ class can be used as archetype
|
|
|
|
TArray<UClass*> ChildrenOfClass;
|
|
GetDerivedClasses(InOldClass, ChildrenOfClass);
|
|
for (auto ClassIt = ChildrenOfClass.CreateConstIterator(); ClassIt; ++ClassIt)
|
|
{
|
|
UClass* ChildClass = *ClassIt;
|
|
UBlueprint* ChildBP = Cast<UBlueprint>(ChildClass->ClassGeneratedBy);
|
|
if (ChildBP && !ChildBP->HasAnyFlags(RF_BeingRegenerated))
|
|
{
|
|
// If this is a direct child, change the parent and relink so the property chain is valid for reinstancing
|
|
if (!ChildBP->HasAnyFlags(RF_NeedLoad))
|
|
{
|
|
if (ChildClass->GetSuperClass() == InOldClass)
|
|
{
|
|
ReparentChild(ChildBP);
|
|
}
|
|
|
|
Children.AddUnique(ChildBP);
|
|
if (ChildBP->ParentClass == InOldClass)
|
|
{
|
|
ChildBP->ParentClass = NewClass;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// If this is a child that caused the load of their parent, relink to the REINST class so that we can still serialize in the CDO, but do not add to later processing
|
|
ReparentChild(ChildClass);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Finally, remove the old class from Root so that it can get GC'd and mark it as CLASS_NewerVersionExists
|
|
InOldClass->RemoveFromRoot();
|
|
InOldClass->ClassFlags |= CLASS_NewerVersionExists;
|
|
}
|
|
|
|
void FHotReloadClassReinstancer::SerializeCDOProperties(UObject* InObject, FHotReloadClassReinstancer::FCDOPropertyData& OutData)
|
|
{
|
|
// Creates a mem-comparable CDO data
|
|
class FCDOWriter : public FMemoryWriter
|
|
{
|
|
/** Objects already visited by this archive */
|
|
TSet<UObject*>& VisitedObjects;
|
|
/** Output property data */
|
|
FCDOPropertyData& PropertyData;
|
|
/** Current subobject being serialized */
|
|
FName SubobjectName;
|
|
|
|
public:
|
|
/** Serializes all script properties of the provided DefaultObject */
|
|
FCDOWriter(FCDOPropertyData& InOutData, UObject* DefaultObject, TSet<UObject*>& InVisitedObjects, FName InSubobjectName = NAME_None)
|
|
: FMemoryWriter(InOutData.Bytes, /* bIsPersistent = */ false, /* bSetOffset = */ true)
|
|
, VisitedObjects(InVisitedObjects)
|
|
, PropertyData(InOutData)
|
|
, SubobjectName(InSubobjectName)
|
|
{
|
|
// Disable delta serialization, we want to serialize everything
|
|
ArNoDelta = true;
|
|
DefaultObject->SerializeScriptProperties(*this);
|
|
}
|
|
virtual void Serialize(void* Data, int64 Num) override
|
|
{
|
|
// Collect serialized properties so we can later update their values on instances if they change
|
|
auto SerializedProperty = GetSerializedProperty();
|
|
if (SerializedProperty != nullptr)
|
|
{
|
|
FCDOProperty& PropertyInfo = PropertyData.Properties.FindOrAdd(SerializedProperty->GetFName());
|
|
if (PropertyInfo.Property == nullptr)
|
|
{
|
|
PropertyInfo.Property = SerializedProperty;
|
|
PropertyInfo.SubobjectName = SubobjectName;
|
|
PropertyInfo.SerializedValueOffset = Tell();
|
|
PropertyInfo.SerializedValueSize = Num;
|
|
PropertyData.Properties.Add(SerializedProperty->GetFName(), PropertyInfo);
|
|
}
|
|
else
|
|
{
|
|
PropertyInfo.SerializedValueSize += Num;
|
|
}
|
|
}
|
|
FMemoryWriter::Serialize(Data, Num);
|
|
}
|
|
/** Serializes an object. Only name and class for normal references, deep serialization for DSOs */
|
|
virtual FArchive& operator<<(class UObject*& InObj) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
if (InObj)
|
|
{
|
|
FName ClassName = InObj->GetClass()->GetFName();
|
|
FName ObjectName = InObj->GetFName();
|
|
Ar << ClassName;
|
|
Ar << ObjectName;
|
|
if (!VisitedObjects.Contains(InObj))
|
|
{
|
|
VisitedObjects.Add(InObj);
|
|
if (Ar.GetSerializedProperty() && Ar.GetSerializedProperty()->ContainsInstancedObjectProperty())
|
|
{
|
|
// Serialize all DSO properties too
|
|
FCDOWriter DefaultSubobjectWriter(PropertyData, InObj, VisitedObjects, InObj->GetFName());
|
|
Seek(PropertyData.Bytes.Num());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
FName UnusedName = NAME_None;
|
|
Ar << UnusedName;
|
|
Ar << UnusedName;
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
/** Serializes an FName as its index and number */
|
|
virtual FArchive& operator<<(FName& InName) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
NAME_INDEX ComparisonIndex = InName.GetComparisonIndex();
|
|
NAME_INDEX DisplayIndex = InName.GetDisplayIndex();
|
|
int32 Number = InName.GetNumber();
|
|
Ar << ComparisonIndex;
|
|
Ar << DisplayIndex;
|
|
Ar << Number;
|
|
return Ar;
|
|
}
|
|
virtual FArchive& operator<<(FLazyObjectPtr& LazyObjectPtr) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
auto UniqueID = LazyObjectPtr.GetUniqueID();
|
|
Ar << UniqueID;
|
|
return *this;
|
|
}
|
|
virtual FArchive& operator<<(FAssetPtr& AssetPtr) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
auto UniqueID = AssetPtr.GetUniqueID();
|
|
Ar << UniqueID;
|
|
return Ar;
|
|
}
|
|
virtual FArchive& operator<<(FStringAssetReference& Value) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
|
|
FString Path = Value.ToString();
|
|
|
|
Ar << Path;
|
|
|
|
if (IsLoading())
|
|
{
|
|
Value.SetPath(MoveTemp(Path));
|
|
}
|
|
|
|
return Ar;
|
|
}
|
|
/** Archive name, for debugging */
|
|
virtual FString GetArchiveName() const override { return TEXT("FCDOWriter"); }
|
|
};
|
|
TSet<UObject*> VisitedObjects;
|
|
VisitedObjects.Add(InObject);
|
|
FCDOWriter Ar(OutData, InObject, VisitedObjects);
|
|
}
|
|
|
|
void FHotReloadClassReinstancer::ReconstructClassDefaultObject(UClass* InClass, UObject* InOuter, FName InName, EObjectFlags InFlags)
|
|
{
|
|
// Get the parent CDO
|
|
UClass* ParentClass = InClass->GetSuperClass();
|
|
UObject* ParentDefaultObject = NULL;
|
|
if (ParentClass != NULL)
|
|
{
|
|
ParentDefaultObject = ParentClass->GetDefaultObject(); // Force the default object to be constructed if it isn't already
|
|
}
|
|
|
|
// Re-create
|
|
InClass->ClassDefaultObject = StaticAllocateObject(InClass, InOuter, InName, InFlags, EInternalObjectFlags::None, false);
|
|
check(InClass->ClassDefaultObject);
|
|
const bool bShouldInitializeProperties = false;
|
|
const bool bCopyTransientsFromClassDefaults = false;
|
|
(*InClass->ClassConstructor)(FObjectInitializer(InClass->ClassDefaultObject, ParentDefaultObject, bCopyTransientsFromClassDefaults, bShouldInitializeProperties));
|
|
}
|
|
|
|
void FHotReloadClassReinstancer::RecreateCDOAndSetupOldClassReinstancing(UClass* InOldClass)
|
|
{
|
|
// Set base class members to valid values
|
|
ClassToReinstance = InOldClass;
|
|
DuplicatedClass = InOldClass;
|
|
OriginalCDO = InOldClass->GetDefaultObject();
|
|
bHasReinstanced = false;
|
|
bSkipGarbageCollection = false;
|
|
bNeedsReinstancing = false;
|
|
NewClass = InOldClass; // The class doesn't change in this case
|
|
|
|
// Collect the original property values
|
|
SerializeCDOProperties(InOldClass->GetDefaultObject(), OriginalCDOProperties);
|
|
|
|
// Remember all the basic info about the object before we rename it
|
|
EObjectFlags CDOFlags = OriginalCDO->GetFlags();
|
|
UObject* CDOOuter = OriginalCDO->GetOuter();
|
|
FName CDOName = OriginalCDO->GetFName();
|
|
|
|
// Rename original CDO, so we can store this one as OverridenArchetypeForCDO
|
|
// and create new one with the same name and outer.
|
|
OriginalCDO->Rename(
|
|
*MakeUniqueObjectName(
|
|
GetTransientPackage(),
|
|
OriginalCDO->GetClass(),
|
|
*FString::Printf(TEXT("BPGC_ARCH_FOR_CDO_%s"), *InOldClass->GetName())
|
|
).ToString(),
|
|
GetTransientPackage(),
|
|
REN_DoNotDirty | REN_DontCreateRedirectors | REN_NonTransactional | REN_SkipGeneratedClasses | REN_ForceNoResetLoaders);
|
|
|
|
// Re-create the CDO, re-running its constructor
|
|
ReconstructClassDefaultObject(InOldClass, CDOOuter, CDOName, CDOFlags);
|
|
|
|
ReconstructedCDOsMap.Add(OriginalCDO, InOldClass->GetDefaultObject());
|
|
|
|
// Collect the property values after re-constructing the CDO
|
|
SerializeCDOProperties(InOldClass->GetDefaultObject(), ReconstructedCDOProperties);
|
|
|
|
// We only want to re-instance the old class if its CDO's values have changed or any of its DSOs' property values have changed
|
|
if (DefaultPropertiesHaveChanged())
|
|
{
|
|
bNeedsReinstancing = true;
|
|
SaveClassFieldMapping(InOldClass);
|
|
|
|
TArray<UClass*> ChildrenOfClass;
|
|
GetDerivedClasses(InOldClass, ChildrenOfClass);
|
|
for (auto ClassIt = ChildrenOfClass.CreateConstIterator(); ClassIt; ++ClassIt)
|
|
{
|
|
UClass* ChildClass = *ClassIt;
|
|
UBlueprint* ChildBP = Cast<UBlueprint>(ChildClass->ClassGeneratedBy);
|
|
if (ChildBP && !ChildBP->HasAnyFlags(RF_BeingRegenerated))
|
|
{
|
|
if (!ChildBP->HasAnyFlags(RF_NeedLoad))
|
|
{
|
|
Children.AddUnique(ChildBP);
|
|
auto BPGC = Cast<UBlueprintGeneratedClass>(ChildBP->GeneratedClass);
|
|
auto CurrentCDO = BPGC ? BPGC->GetDefaultObject(false) : nullptr;
|
|
if (CurrentCDO && (OriginalCDO == CurrentCDO->GetArchetype()))
|
|
{
|
|
BPGC->OverridenArchetypeForCDO = OriginalCDO;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
FHotReloadClassReinstancer::FHotReloadClassReinstancer(UClass* InNewClass, UClass* InOldClass, const TMap<UClass*, UClass*>& InOldToNewClassesMap, TMap<UObject*, UObject*>& OutReconstructedCDOsMap, TSet<UBlueprint*>& InBPSetToRecompile, TSet<UBlueprint*>& InBPSetToRecompileBytecodeOnly)
|
|
: NewClass(nullptr)
|
|
, bNeedsReinstancing(false)
|
|
, CopyOfPreviousCDO(nullptr)
|
|
, ReconstructedCDOsMap(OutReconstructedCDOsMap)
|
|
, BPSetToRecompile(InBPSetToRecompile)
|
|
, BPSetToRecompileBytecodeOnly(InBPSetToRecompileBytecodeOnly)
|
|
, OldToNewClassesMap(InOldToNewClassesMap)
|
|
{
|
|
ensure(InOldClass);
|
|
ensure(!HotReloadedOldClass && !HotReloadedNewClass);
|
|
HotReloadedOldClass = InOldClass;
|
|
HotReloadedNewClass = InNewClass ? InNewClass : InOldClass;
|
|
|
|
for (const TPair<UClass*, UClass*>& OldToNewClass : OldToNewClassesMap)
|
|
{
|
|
ObjectsThatShouldUseOldStuff.Add(OldToNewClass.Key);
|
|
}
|
|
|
|
// If InNewClass is NULL, then the old class has not changed after hot-reload.
|
|
// However, we still need to check for changes to its constructor code (CDO values).
|
|
if (InNewClass)
|
|
{
|
|
SetupNewClassReinstancing(InNewClass, InOldClass);
|
|
|
|
TMap<UObject*, UObject*> ClassRedirects;
|
|
ClassRedirects.Add(InOldClass, InNewClass);
|
|
|
|
for (TObjectIterator<UBlueprint> BlueprintIt; BlueprintIt; ++BlueprintIt)
|
|
{
|
|
FArchiveReplaceObjectRef<UObject> ReplaceObjectArch(*BlueprintIt, ClassRedirects, false, true, true);
|
|
if (ReplaceObjectArch.GetCount())
|
|
{
|
|
EnlistDependentBlueprintToRecompile(*BlueprintIt, false);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
RecreateCDOAndSetupOldClassReinstancing(InOldClass);
|
|
}
|
|
}
|
|
|
|
FHotReloadClassReinstancer::~FHotReloadClassReinstancer()
|
|
{
|
|
// Make sure the base class does not remove the DuplicatedClass from root, we not always want it.
|
|
// For example when we're just reconstructing CDOs. Other cases are handled by HotReloadClassReinstancer.
|
|
DuplicatedClass = nullptr;
|
|
|
|
ensure(HotReloadedOldClass);
|
|
HotReloadedOldClass = nullptr;
|
|
HotReloadedNewClass = nullptr;
|
|
}
|
|
|
|
/** Helper for finding subobject in an array. Usually there's not that many subobjects on a class to justify a TMap */
|
|
FORCEINLINE static UObject* FindDefaultSubobject(TArray<UObject*>& InDefaultSubobjects, FName SubobjectName)
|
|
{
|
|
for (auto Subobject : InDefaultSubobjects)
|
|
{
|
|
if (Subobject->GetFName() == SubobjectName)
|
|
{
|
|
return Subobject;
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void FHotReloadClassReinstancer::UpdateDefaultProperties()
|
|
{
|
|
struct FPropertyToUpdate
|
|
{
|
|
UProperty* Property;
|
|
FName SubobjectName;
|
|
uint8* OldSerializedValuePtr;
|
|
uint8* NewValuePtr;
|
|
int64 OldSerializedSize;
|
|
};
|
|
/** Memory writer archive that supports UObject values the same way as FCDOWriter. */
|
|
class FPropertyValueMemoryWriter : public FMemoryWriter
|
|
{
|
|
public:
|
|
FPropertyValueMemoryWriter(TArray<uint8>& OutData)
|
|
: FMemoryWriter(OutData)
|
|
{}
|
|
virtual FArchive& operator<<(class UObject*& InObj) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
if (InObj)
|
|
{
|
|
FName ClassName = InObj->GetClass()->GetFName();
|
|
FName ObjectName = InObj->GetFName();
|
|
Ar << ClassName;
|
|
Ar << ObjectName;
|
|
}
|
|
else
|
|
{
|
|
FName UnusedName = NAME_None;
|
|
Ar << UnusedName;
|
|
Ar << UnusedName;
|
|
}
|
|
return *this;
|
|
}
|
|
virtual FArchive& operator<<(FName& InName) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
NAME_INDEX ComparisonIndex = InName.GetComparisonIndex();
|
|
NAME_INDEX DisplayIndex = InName.GetDisplayIndex();
|
|
int32 Number = InName.GetNumber();
|
|
Ar << ComparisonIndex;
|
|
Ar << DisplayIndex;
|
|
Ar << Number;
|
|
return Ar;
|
|
}
|
|
virtual FArchive& operator<<(FLazyObjectPtr& LazyObjectPtr) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
auto UniqueID = LazyObjectPtr.GetUniqueID();
|
|
Ar << UniqueID;
|
|
return *this;
|
|
}
|
|
virtual FArchive& operator<<(FAssetPtr& AssetPtr) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
auto UniqueID = AssetPtr.GetUniqueID();
|
|
Ar << UniqueID;
|
|
return Ar;
|
|
}
|
|
virtual FArchive& operator<<(FStringAssetReference& Value) override
|
|
{
|
|
FArchive& Ar = *this;
|
|
|
|
FString Path = Value.ToString();
|
|
|
|
Ar << Path;
|
|
|
|
if (IsLoading())
|
|
{
|
|
Value.SetPath(MoveTemp(Path));
|
|
}
|
|
|
|
return Ar;
|
|
}
|
|
};
|
|
|
|
// Collect default subobjects to update their properties too
|
|
const int32 DefaultSubobjectArrayCapacity = 16;
|
|
TArray<UObject*> DefaultSubobjectArray;
|
|
DefaultSubobjectArray.Empty(DefaultSubobjectArrayCapacity);
|
|
NewClass->GetDefaultObject()->CollectDefaultSubobjects(DefaultSubobjectArray);
|
|
|
|
TArray<FPropertyToUpdate> PropertiesToUpdate;
|
|
// Collect all properties that have actually changed
|
|
for (auto& Pair : ReconstructedCDOProperties.Properties)
|
|
{
|
|
auto OldPropertyInfo = OriginalCDOProperties.Properties.Find(Pair.Key);
|
|
if (OldPropertyInfo)
|
|
{
|
|
auto& NewPropertyInfo = Pair.Value;
|
|
|
|
uint8* OldSerializedValuePtr = OriginalCDOProperties.Bytes.GetData() + OldPropertyInfo->SerializedValueOffset;
|
|
uint8* NewSerializedValuePtr = ReconstructedCDOProperties.Bytes.GetData() + NewPropertyInfo.SerializedValueOffset;
|
|
if (OldPropertyInfo->SerializedValueSize != NewPropertyInfo.SerializedValueSize ||
|
|
FMemory::Memcmp(OldSerializedValuePtr, NewSerializedValuePtr, OldPropertyInfo->SerializedValueSize) != 0)
|
|
{
|
|
// Property value has changed so add it to the list of properties that need updating on instances
|
|
FPropertyToUpdate PropertyToUpdate;
|
|
PropertyToUpdate.Property = NewPropertyInfo.Property;
|
|
PropertyToUpdate.NewValuePtr = nullptr;
|
|
PropertyToUpdate.SubobjectName = NewPropertyInfo.SubobjectName;
|
|
|
|
if (NewPropertyInfo.Property->GetOuter() == NewClass)
|
|
{
|
|
PropertyToUpdate.NewValuePtr = PropertyToUpdate.Property->ContainerPtrToValuePtr<uint8>(NewClass->GetDefaultObject());
|
|
}
|
|
else if (NewPropertyInfo.SubobjectName != NAME_None)
|
|
{
|
|
UObject* DefaultSubobjectPtr = FindDefaultSubobject(DefaultSubobjectArray, NewPropertyInfo.SubobjectName);
|
|
if (DefaultSubobjectPtr && NewPropertyInfo.Property->GetOuter() == DefaultSubobjectPtr->GetClass())
|
|
{
|
|
PropertyToUpdate.NewValuePtr = PropertyToUpdate.Property->ContainerPtrToValuePtr<uint8>(DefaultSubobjectPtr);
|
|
}
|
|
}
|
|
if (PropertyToUpdate.NewValuePtr)
|
|
{
|
|
PropertyToUpdate.OldSerializedValuePtr = OldSerializedValuePtr;
|
|
PropertyToUpdate.OldSerializedSize = OldPropertyInfo->SerializedValueSize;
|
|
|
|
PropertiesToUpdate.Add(PropertyToUpdate);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (PropertiesToUpdate.Num())
|
|
{
|
|
TArray<uint8> CurrentValueSerializedData;
|
|
|
|
// Update properties on all existing instances of the class
|
|
for (FObjectIterator It(NewClass); It; ++It)
|
|
{
|
|
UObject* ObjectPtr = *It;
|
|
DefaultSubobjectArray.Empty(DefaultSubobjectArrayCapacity);
|
|
ObjectPtr->CollectDefaultSubobjects(DefaultSubobjectArray);
|
|
|
|
for (auto& PropertyToUpdate : PropertiesToUpdate)
|
|
{
|
|
uint8* InstanceValuePtr = nullptr;
|
|
if (PropertyToUpdate.SubobjectName == NAME_None)
|
|
{
|
|
InstanceValuePtr = PropertyToUpdate.Property->ContainerPtrToValuePtr<uint8>(ObjectPtr);
|
|
}
|
|
else
|
|
{
|
|
UObject* DefaultSubobjectPtr = FindDefaultSubobject(DefaultSubobjectArray, PropertyToUpdate.SubobjectName);
|
|
if (DefaultSubobjectPtr && PropertyToUpdate.Property->GetOuter() == DefaultSubobjectPtr->GetClass())
|
|
{
|
|
InstanceValuePtr = PropertyToUpdate.Property->ContainerPtrToValuePtr<uint8>(DefaultSubobjectPtr);
|
|
}
|
|
}
|
|
|
|
if (InstanceValuePtr)
|
|
{
|
|
// Serialize current value to a byte array as we don't have the previous CDO to compare against, we only have its serialized property data
|
|
CurrentValueSerializedData.Empty(CurrentValueSerializedData.Num() + CurrentValueSerializedData.GetSlack());
|
|
FPropertyValueMemoryWriter CurrentValueWriter(CurrentValueSerializedData);
|
|
PropertyToUpdate.Property->SerializeItem(CurrentValueWriter, InstanceValuePtr);
|
|
|
|
// Update only when the current value on the instance is identical to the original CDO
|
|
if (CurrentValueSerializedData.Num() == PropertyToUpdate.OldSerializedSize &&
|
|
FMemory::Memcmp(CurrentValueSerializedData.GetData(), PropertyToUpdate.OldSerializedValuePtr, CurrentValueSerializedData.Num()) == 0)
|
|
{
|
|
// Update with the new value
|
|
PropertyToUpdate.Property->CopyCompleteValue(InstanceValuePtr, PropertyToUpdate.NewValuePtr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void FHotReloadClassReinstancer::ReinstanceObjectsAndUpdateDefaults()
|
|
{
|
|
ReinstanceObjects(true);
|
|
UpdateDefaultProperties();
|
|
}
|
|
|
|
void FHotReloadClassReinstancer::AddReferencedObjects(FReferenceCollector& Collector)
|
|
{
|
|
FBlueprintCompileReinstancer::AddReferencedObjects(Collector);
|
|
Collector.AllowEliminatingReferences(false);
|
|
Collector.AddReferencedObject(CopyOfPreviousCDO);
|
|
Collector.AllowEliminatingReferences(true);
|
|
}
|
|
|
|
void FHotReloadClassReinstancer::EnlistDependentBlueprintToRecompile(UBlueprint* BP, bool bBytecodeOnly)
|
|
{
|
|
if (IsValid(BP))
|
|
{
|
|
if (bBytecodeOnly)
|
|
{
|
|
if (!BPSetToRecompile.Contains(BP) && !BPSetToRecompileBytecodeOnly.Contains(BP))
|
|
{
|
|
BPSetToRecompileBytecodeOnly.Add(BP);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!BPSetToRecompile.Contains(BP))
|
|
{
|
|
if (BPSetToRecompileBytecodeOnly.Contains(BP))
|
|
{
|
|
BPSetToRecompileBytecodeOnly.Remove(BP);
|
|
}
|
|
|
|
BPSetToRecompile.Add(BP);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void FHotReloadClassReinstancer::BlueprintWasRecompiled(UBlueprint* BP, bool bBytecodeOnly)
|
|
{
|
|
BPSetToRecompile.Remove(BP);
|
|
BPSetToRecompileBytecodeOnly.Remove(BP);
|
|
|
|
FBlueprintCompileReinstancer::BlueprintWasRecompiled(BP, bBytecodeOnly);
|
|
}
|
|
|
|
#endif
|