├── .gitignore ├── BlueprintRetarget.uplugin ├── Config └── FilterPlugin.ini ├── Content └── Readme │ ├── ContextMenu.png │ ├── SelectClass.png │ └── Warning.png ├── LICENSE ├── README.md └── Source └── BlueprintRetarget ├── BlueprintRetarget.Build.cs ├── Private ├── BlueprintRetarget.cpp ├── ContentBrowserExtensions.cpp └── ContentBrowserExtensions.h └── Public └── BlueprintRetarget.h /.gitignore: -------------------------------------------------------------------------------- 1 | /Binaries 2 | /Intermediate -------------------------------------------------------------------------------- /BlueprintRetarget.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0", 5 | "FriendlyName": "Blueprint Retarget", 6 | "Description": "A simple tool that helps retarget blueprints with invalid parent classes", 7 | "Category": "Other", 8 | "CreatedBy": "Piperift", 9 | "CreatedByURL": "https://piperift.com", 10 | "DocsURL": "", 11 | "MarketplaceURL": "", 12 | "SupportURL": "", 13 | "CanContainContent": false, 14 | "IsBetaVersion": false, 15 | "Modules": [ 16 | { 17 | "Name": "BlueprintRetarget", 18 | "Type": "Editor", 19 | "LoadingPhase": "Default" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /Config/FilterPlugin.ini: -------------------------------------------------------------------------------- 1 | [FilterPlugin] 2 | ; This section lists additional files which will be packaged along with your plugin. Paths should be listed relative to the root plugin directory, and 3 | ; may include "...", "*", and "?" wildcards to match directories, files, and individual characters respectively. 4 | ; 5 | ; Examples: 6 | ; /README.txt 7 | ; /Extras/... 8 | ; /Binaries/ThirdParty/*.dll 9 | -------------------------------------------------------------------------------- /Content/Readme/ContextMenu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PipeRift/BlueprintRetarget/a7e3cb959dd4a8902d29d3a6947dfbb21b575524/Content/Readme/ContextMenu.png -------------------------------------------------------------------------------- /Content/Readme/SelectClass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PipeRift/BlueprintRetarget/a7e3cb959dd4a8902d29d3a6947dfbb21b575524/Content/Readme/SelectClass.png -------------------------------------------------------------------------------- /Content/Readme/Warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PipeRift/BlueprintRetarget/a7e3cb959dd4a8902d29d3a6947dfbb21b575524/Content/Readme/Warning.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Blueprint Retarget plugin 2 | An small tool that allows retargeting invalid blueprints when its parent class is missing on UE4 3 | 4 | ## When to Use 5 | Use this tool when a blueprint has a missing parent class (and therefore you can't open it). 6 | 7 | This can happen when: 8 | - It's parent C++ class has been renamed, changed its module or is missing for any other reason. 9 | - It's parent Blueprint class has been lost but still exists somewhere. 10 | 11 | Only retarget classes with their original, not modified, parent classes. 12 | 13 | ### This is not a magic fix button 14 | 15 | It won't fix references and blueprints could still fail if the parent has changed or if anything else is corrupted. 16 | 17 | **Use it only when the parent class is missing.** 18 | 19 | ## Usage 20 | 21 | 1. When having an invalid blueprint, right click on it to see *"Retarget invalid parent"* 22 | 23 | 24 | 25 | 2. After this, a warning will pop up... to warn you 26 | 27 | 28 | 29 | 3. Finally, select the missing parent from the list. The blueprint will be reparented and you should be able to use it again. 30 | 31 | -------------------------------------------------------------------------------- /Source/BlueprintRetarget/BlueprintRetarget.Build.cs: -------------------------------------------------------------------------------- 1 | // Copyright 1998-2018 Epic Games, Inc. All Rights Reserved. 2 | 3 | using UnrealBuildTool; 4 | 5 | public class BlueprintRetarget : ModuleRules 6 | { 7 | public BlueprintRetarget(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicDependencyModuleNames.AddRange(new string[] { 12 | "Core" 13 | }); 14 | 15 | PrivateDependencyModuleNames.AddRange(new string[] { 16 | "Projects", 17 | "InputCore", 18 | "UnrealEd", 19 | "CoreUObject", 20 | "Engine", 21 | "EditorStyle", 22 | "SlateCore", 23 | "Slate", 24 | "BlueprintGraph" 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Source/BlueprintRetarget/Private/BlueprintRetarget.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2020 Piperift. All Rights Reserved. 2 | 3 | #include "BlueprintRetarget.h" 4 | #include "ContentBrowserExtensions.h" 5 | 6 | 7 | #define LOCTEXT_NAMESPACE "FBlueprintRetargetModule" 8 | 9 | DEFINE_LOG_CATEGORY(LogBlueprintReparent); 10 | 11 | 12 | static const FName BlueprintRetargetTabName("BlueprintRetarget"); 13 | 14 | void FBlueprintRetargetModule::StartupModule() 15 | { 16 | FBlueprintRetargetContentBrowserExtensions::InstallHooks(); 17 | } 18 | 19 | void FBlueprintRetargetModule::ShutdownModule() 20 | { 21 | FBlueprintRetargetContentBrowserExtensions::RemoveHooks(); 22 | } 23 | 24 | #undef LOCTEXT_NAMESPACE 25 | 26 | IMPLEMENT_MODULE(FBlueprintRetargetModule, BlueprintRetarget) -------------------------------------------------------------------------------- /Source/BlueprintRetarget/Private/ContentBrowserExtensions.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2020 Piperift. All Rights Reserved. 2 | 3 | #include "ContentBrowserExtensions.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | #define LOCTEXT_NAMESPACE "BlueprintRetarget" 40 | 41 | 42 | class FRetargetBlueprintFilter : public IClassViewerFilter 43 | { 44 | public: 45 | /** All children of these classes will be included unless filtered out by another setting. */ 46 | TSet< const UClass* > AllowedChildrenOfClasses; 47 | 48 | /** Classes to not allow any children of into the Class Viewer/Picker. */ 49 | TSet< const UClass* > DisallowedChildrenOfClasses; 50 | 51 | /** Classes to never show in this class viewer. */ 52 | TSet< const UClass* > DisallowedClasses; 53 | 54 | /** Will limit the results to only native classes */ 55 | bool bShowNativeOnly; 56 | 57 | FRetargetBlueprintFilter() 58 | : bShowNativeOnly(false) 59 | {} 60 | 61 | virtual bool IsClassAllowed(const FClassViewerInitializationOptions& InInitOptions, const UClass* InClass, TSharedRef< FClassViewerFilterFuncs > InFilterFuncs) override 62 | { 63 | // If it appears on the allowed child-of classes list (or there is nothing on that list) 64 | // AND it is NOT on the disallowed child-of classes list 65 | // AND it is NOT on the disallowed classes list 66 | return InFilterFuncs->IfInChildOfClassesSet(AllowedChildrenOfClasses, InClass) != EFilterReturn::Failed && 67 | InFilterFuncs->IfInChildOfClassesSet(DisallowedChildrenOfClasses, InClass) != EFilterReturn::Passed && 68 | InFilterFuncs->IfInClassesSet(DisallowedClasses, InClass) != EFilterReturn::Passed && 69 | !InClass->HasAnyClassFlags(CLASS_Deprecated) && 70 | ((bShowNativeOnly && InClass->HasAnyClassFlags(CLASS_Native)) || !bShowNativeOnly); 71 | } 72 | 73 | virtual bool IsUnloadedClassAllowed(const FClassViewerInitializationOptions& InInitOptions, const TSharedRef< const IUnloadedBlueprintData > InUnloadedClassData, TSharedRef< FClassViewerFilterFuncs > InFilterFuncs) override 74 | { 75 | // If it appears on the allowed child-of classes list (or there is nothing on that list) 76 | // AND it is NOT on the disallowed child-of classes list 77 | // AND it is NOT on the disallowed classes list 78 | return InFilterFuncs->IfInChildOfClassesSet(AllowedChildrenOfClasses, InUnloadedClassData) != EFilterReturn::Failed && 79 | InFilterFuncs->IfInChildOfClassesSet(DisallowedChildrenOfClasses, InUnloadedClassData) != EFilterReturn::Passed && 80 | InFilterFuncs->IfInClassesSet(DisallowedClasses, InUnloadedClassData) != EFilterReturn::Passed && 81 | !InUnloadedClassData->HasAnyClassFlags(CLASS_Deprecated) && 82 | ((bShowNativeOnly && InUnloadedClassData->HasAnyClassFlags(CLASS_Native)) || !bShowNativeOnly); 83 | } 84 | }; 85 | 86 | 87 | ////////////////////////////////////////////////////////////////////////// 88 | 89 | FContentBrowserMenuExtender_SelectedAssets ContentBrowserExtenderDelegate; 90 | FDelegateHandle ContentBrowserExtenderDelegateHandle; 91 | 92 | 93 | ////////////////////////////////////////////////////////////////////////// 94 | // FContentBrowserSelectedAssetExtensionBase 95 | 96 | struct FContentBrowserSelectedAssetExtensionBase 97 | { 98 | public: 99 | TArray SelectedAssets; 100 | 101 | public: 102 | virtual void Execute() {} 103 | virtual ~FContentBrowserSelectedAssetExtensionBase() {} 104 | }; 105 | 106 | 107 | ////////////////////////////////////////////////////////////////////////// 108 | // FRetargetClassExtension 109 | 110 | struct FRetargetClassExtension : public FContentBrowserSelectedAssetExtensionBase 111 | { 112 | FRetargetClassExtension() 113 | {} 114 | 115 | virtual void Execute() override 116 | { 117 | // Only cache Blueprint assets 118 | TArray BPs; 119 | for (auto AssetIt = SelectedAssets.CreateConstIterator(); AssetIt; ++AssetIt) 120 | { 121 | const FAssetData& AssetData = *AssetIt; 122 | if (TAssetPtr BP = Cast(AssetData.GetAsset())) 123 | { 124 | BPs.Add(BP.Get()); 125 | } 126 | } 127 | 128 | const FText WarningTitle = LOCTEXT("RetargetWarningTitle", "WARNING"); 129 | EAppReturnType::Type Result = FMessageDialog::Open(EAppMsgType::OkCancel, EAppReturnType::Ok, 130 | LOCTEXT("RetargetWarning", "This tool is ONLY intended to fix missing or invalid blueprint parents.\n\nDo not try to reparent a working blueprint with it. Assigning parent classes that changed or are unrelated may corrupt your blueprint."), 131 | &WarningTitle 132 | ); 133 | 134 | if (Result == EAppReturnType::Cancel) 135 | return; 136 | 137 | // Assign a new parent class 138 | UClass* ChosenClass{ SelectClass(BPs) }; 139 | 140 | if (ChosenClass) 141 | { 142 | const FScopedTransaction Transaction(LOCTEXT("RetargetBlueprintParents", "Retarget Blueprint parents")); 143 | for (auto* BP : BPs) 144 | { 145 | ReparentBlueprint(BP, ChosenClass); 146 | } 147 | } 148 | } 149 | 150 | UClass* SelectClass(const TArray& BPs) 151 | { 152 | // Class picker options 153 | FClassViewerInitializationOptions Options; 154 | { 155 | Options.Mode = EClassViewerMode::ClassPicker; 156 | Options.DisplayMode = EClassViewerDisplayMode::TreeView; 157 | Options.bShowObjectRootClass = true; 158 | 159 | Options.bIsBlueprintBaseOnly = true; // Only want blueprint base classes 160 | Options.bShowUnloadedBlueprints = true; 161 | 162 | Options.ClassFilter = PrepareFilter(BPs); 163 | } 164 | 165 | // Temporally hide custom picker from ClassPicker 166 | bool bLastExpandCustomClasses = true; 167 | GConfig->GetBool(TEXT("/Script/UnrealEd.UnrealEdOptions"), TEXT("bExpandClassPickerDefaultClassList"), bLastExpandCustomClasses, GEditorIni); 168 | GConfig->SetBool(TEXT("/Script/UnrealEd.UnrealEdOptions"), TEXT("bExpandClassPickerDefaultClassList"), false, GEditorIni); 169 | 170 | UClass* ChosenClass = nullptr; 171 | const FText TitleText = LOCTEXT("ClassPickerTitle", "Pick Parent Class"); 172 | const bool bPressedOk = SClassPickerDialog::PickClass(TitleText, Options, ChosenClass, UBlueprint::StaticClass()); 173 | 174 | // Restore custom picker config value 175 | GConfig->SetBool(TEXT("/Script/UnrealEd.UnrealEdOptions"), TEXT("bExpandClassPickerDefaultClassList"), bLastExpandCustomClasses, GEditorIni); 176 | 177 | 178 | return bPressedOk? ChosenClass : nullptr; 179 | } 180 | 181 | TSharedPtr PrepareFilter(const TArray BPs) 182 | { 183 | // Gather BP information 184 | TArray BlueprintClasses{}; 185 | bool bHasParent = true; 186 | bool bIsActor = false; 187 | bool bIsAnimBlueprint = false; 188 | bool bIsLevelScriptActor = false; 189 | bool bIsComponentBlueprint = false; 190 | for (auto BlueprintIt = BPs.CreateConstIterator(); (!bIsActor && !bIsAnimBlueprint) && BlueprintIt; ++BlueprintIt) 191 | { 192 | const UBlueprint* Blueprint = *BlueprintIt; 193 | 194 | bIsAnimBlueprint |= Blueprint->IsA(UAnimBlueprint::StaticClass()); 195 | 196 | if (Blueprint->ParentClass) 197 | { 198 | bIsActor |= Blueprint->ParentClass->IsChildOf(AActor::StaticClass()); 199 | bIsLevelScriptActor |= Blueprint->ParentClass->IsChildOf(ALevelScriptActor::StaticClass()); 200 | bIsComponentBlueprint |= Blueprint->ParentClass->IsChildOf(UActorComponent::StaticClass()); 201 | if (Blueprint->GeneratedClass) 202 | { 203 | BlueprintClasses.Add(Blueprint->GeneratedClass); 204 | } 205 | } 206 | else 207 | { 208 | bHasParent = false; 209 | } 210 | } 211 | 212 | 213 | TSharedPtr Filter = MakeShared(); 214 | 215 | Filter->DisallowedChildrenOfClasses.Add(UInterface::StaticClass()); 216 | Filter->DisallowedChildrenOfClasses.Append(BlueprintClasses); // Can't re-parent to child BPs 217 | for (UBlueprint* BP : BPs) 218 | { 219 | BP->GetReparentingRules(Filter->AllowedChildrenOfClasses, Filter->DisallowedChildrenOfClasses); 220 | } 221 | 222 | if (bIsActor) 223 | { 224 | if (bIsLevelScriptActor) 225 | { 226 | // Don't allow conversion outside of the LevelScriptActor hierarchy 227 | Filter->AllowedChildrenOfClasses.Add(ALevelScriptActor::StaticClass()); 228 | Filter->bShowNativeOnly = true; 229 | } 230 | else 231 | { 232 | // Don't allow conversion outside of the Actor hierarchy 233 | Filter->AllowedChildrenOfClasses.Add(AActor::StaticClass()); 234 | 235 | // Don't allow non-LevelScriptActor->LevelScriptActor conversion 236 | Filter->DisallowedChildrenOfClasses.Add(ALevelScriptActor::StaticClass()); 237 | } 238 | } 239 | else if (bIsAnimBlueprint) 240 | { 241 | // If it's an anim blueprint, do not allow conversion to non anim 242 | Filter->AllowedChildrenOfClasses.Add(UAnimInstance::StaticClass()); 243 | } 244 | else if (bIsComponentBlueprint) 245 | { 246 | // If it is a component blueprint, only allow classes under and including UActorComponent 247 | Filter->AllowedChildrenOfClasses.Add(UActorComponent::StaticClass()); 248 | } 249 | else if(bHasParent) 250 | { 251 | Filter->DisallowedChildrenOfClasses.Add(AActor::StaticClass()); 252 | } 253 | 254 | for (const UBlueprint* BP : BPs) 255 | { 256 | // don't allow making me my own parent! 257 | if (BP->GeneratedClass) 258 | { 259 | Filter->DisallowedClasses.Add(BP->GeneratedClass); 260 | } 261 | } 262 | return Filter; 263 | } 264 | 265 | void ReparentBlueprint(UBlueprint* Blueprint, UClass* ChosenClass) { 266 | check(Blueprint); 267 | 268 | if ((Blueprint != nullptr) && (ChosenClass != nullptr) && (ChosenClass != Blueprint->ParentClass)) 269 | { 270 | // Notify user, about common interfaces 271 | bool bReparent = true; 272 | { 273 | FString CommonInterfacesNames; 274 | for (const FBPInterfaceDescription& InterdaceDesc : Blueprint->ImplementedInterfaces) 275 | { 276 | if (ChosenClass->ImplementsInterface(*InterdaceDesc.Interface)) 277 | { 278 | CommonInterfacesNames += InterdaceDesc.Interface->GetName(); 279 | CommonInterfacesNames += TCHAR('\n'); 280 | } 281 | } 282 | if (!CommonInterfacesNames.IsEmpty()) 283 | { 284 | const FText Title = LOCTEXT("CommonInterfacesTitle", "Common interfaces"); 285 | const FText Message = FText::Format( 286 | LOCTEXT("ReparentWarning_InterfacesImplemented", "Following interfaces are already implemented. Continue reparenting? \n {0}"), 287 | FText::FromString(CommonInterfacesNames)); 288 | 289 | FSuppressableWarningDialog::FSetupInfo Info(Message, Title, "Warning_CommonInterfacesWhileReparenting"); 290 | Info.ConfirmText = LOCTEXT("ReparentYesButton", "Reparent"); 291 | Info.CancelText = LOCTEXT("ReparentNoButton", "Cancel"); 292 | 293 | if (FSuppressableWarningDialog(Info).ShowModal() == FSuppressableWarningDialog::Cancel) 294 | { 295 | bReparent = false; 296 | } 297 | } 298 | } 299 | 300 | // If the chosen class differs hierarchically from the current class, warn that there may be data loss 301 | if (bReparent && (!Blueprint->ParentClass || !ChosenClass->GetDefaultObject()->IsA(Blueprint->ParentClass))) 302 | { 303 | const FText Title = LOCTEXT("ReparentTitle", "Reparent Blueprint"); 304 | const FText Message = LOCTEXT("ReparentWarning", "Reparenting this blueprint may cause data loss. Continue reparenting?"); 305 | 306 | // Warn the user that this may result in data loss 307 | FSuppressableWarningDialog::FSetupInfo Info(Message, Title, "Warning_ReparentTitle"); 308 | Info.ConfirmText = LOCTEXT("ReparentYesButton", "Reparent"); 309 | Info.CancelText = LOCTEXT("ReparentNoButton", "Cancel"); 310 | Info.CheckBoxText = FText::GetEmpty(); // not suppressible 311 | 312 | if (FSuppressableWarningDialog(Info).ShowModal() == FSuppressableWarningDialog::Cancel) 313 | { 314 | bReparent = false; 315 | } 316 | } 317 | 318 | if (bReparent) 319 | { 320 | UE_LOG(LogBlueprintReparent, Warning, TEXT("Reparenting blueprint %s from %s to %s..."), *Blueprint->GetFullName(), Blueprint->ParentClass ? *Blueprint->ParentClass->GetName() : TEXT("[None]"), *ChosenClass->GetName()); 321 | 322 | UClass* OldParentClass = Blueprint->ParentClass; 323 | Blueprint->ParentClass = ChosenClass; 324 | 325 | // Ensure that the Blueprint is up-to-date (valid SCS etc.) before compiling 326 | EnsureBlueprintIsUpToDate(Blueprint); 327 | FBlueprintEditorUtils::RefreshAllNodes(Blueprint); 328 | FBlueprintEditorUtils::MarkBlueprintAsModified(Blueprint); 329 | 330 | Compile(Blueprint); 331 | 332 | // Ensure that the Blueprint is up-to-date (valid SCS etc.) after compiling (new parent class) 333 | EnsureBlueprintIsUpToDate(Blueprint); 334 | 335 | if (Blueprint->NativizationFlag != EBlueprintNativizationFlag::Disabled) 336 | { 337 | UBlueprint* ParentBlueprint = UBlueprint::GetBlueprintFromClass(ChosenClass); 338 | if (ParentBlueprint && ParentBlueprint->NativizationFlag == EBlueprintNativizationFlag::Disabled) 339 | { 340 | ParentBlueprint->NativizationFlag = EBlueprintNativizationFlag::Dependency; 341 | 342 | FNotificationInfo Warning(FText::Format( 343 | LOCTEXT("InterfaceFlaggedForNativization", "{0} flagged for nativization (as a required dependency)."), 344 | FText::FromName(ParentBlueprint->GetFName()) 345 | )); 346 | Warning.ExpireDuration = 5.0f; 347 | Warning.bFireAndForget = true; 348 | Warning.Image = FCoreStyle::Get().GetBrush(TEXT("MessageLog.Warning")); 349 | FSlateNotificationManager::Get().AddNotification(Warning); 350 | } 351 | } 352 | 353 | /*if (SCSEditor.IsValid()) 354 | { 355 | SCSEditor->UpdateTree(); 356 | }*/ 357 | } 358 | } 359 | 360 | FSlateApplication::Get().DismissAllMenus(); 361 | } 362 | 363 | void Compile(UBlueprint* Blueprint) { 364 | check(Blueprint); 365 | 366 | FCompilerResultsLog LogResults; 367 | LogResults.SetSourcePath(Blueprint->GetPathName()); 368 | LogResults.BeginEvent(TEXT("Compile")); 369 | FKismetEditorUtilities::CompileBlueprint(Blueprint, EBlueprintCompileOptions::None, &LogResults); 370 | 371 | LogResults.EndEvent(); 372 | } 373 | 374 | void EnsureBlueprintIsUpToDate(UBlueprint* Blueprint) { 375 | 376 | // Purge any nullptr graphs 377 | FBlueprintEditorUtils::PurgeNullGraphs(Blueprint); 378 | 379 | // Make sure the blueprint is cosmetically up to date 380 | FKismetEditorUtilities::UpgradeCosmeticallyStaleBlueprint(Blueprint); 381 | 382 | if (FBlueprintEditorUtils::SupportsConstructionScript(Blueprint)) 383 | { 384 | // If we don't have an SCS yet, make it 385 | if (Blueprint->GeneratedClass && !Blueprint->SimpleConstructionScript) 386 | { 387 | Blueprint->SimpleConstructionScript = NewObject(Blueprint->GeneratedClass); 388 | Blueprint->SimpleConstructionScript->SetFlags(RF_Transactional); 389 | } 390 | 391 | // If we should have a UCS but don't yet, make it 392 | if (!FBlueprintEditorUtils::FindUserConstructionScript(Blueprint)) 393 | { 394 | UEdGraph* UCSGraph = FBlueprintEditorUtils::CreateNewGraph(Blueprint, UEdGraphSchema_K2::FN_UserConstructionScript, UEdGraph::StaticClass(), UEdGraphSchema_K2::StaticClass()); 395 | FBlueprintEditorUtils::AddFunctionGraph(Blueprint, UCSGraph, /*bIsUserCreated=*/ false, AActor::StaticClass()); 396 | UCSGraph->bAllowDeletion = false; 397 | } 398 | 399 | // Check to see if we have gained a component from our parent (that would require us removing our scene root) 400 | // (or lost one, which requires adding one) 401 | if (Blueprint->SimpleConstructionScript != nullptr) 402 | { 403 | Blueprint->SimpleConstructionScript->ValidateSceneRootNodes(); 404 | } 405 | } 406 | else 407 | { 408 | // If we have an SCS but don't support it, then we remove it 409 | if (Blueprint->SimpleConstructionScript) 410 | { 411 | // Remove any SCS variable nodes 412 | for (USCS_Node* SCS_Node : Blueprint->SimpleConstructionScript->GetAllNodes()) 413 | { 414 | if (SCS_Node) 415 | { 416 | FBlueprintEditorUtils::RemoveVariableNodes(Blueprint, SCS_Node->GetVariableName()); 417 | } 418 | } 419 | 420 | // Remove the SCS object reference 421 | Blueprint->SimpleConstructionScript = nullptr; 422 | 423 | // Mark the Blueprint as having been structurally modified 424 | FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(Blueprint); 425 | } 426 | } 427 | 428 | // Make sure that this blueprint is up-to-date with regards to its parent functions 429 | FBlueprintEditorUtils::ConformCallsToParentFunctions(Blueprint); 430 | 431 | // Make sure that this blueprint is up-to-date with regards to its implemented events 432 | FBlueprintEditorUtils::ConformImplementedEvents(Blueprint); 433 | 434 | // Make sure that this blueprint is up-to-date with regards to its implemented interfaces 435 | FBlueprintEditorUtils::ConformImplementedInterfaces(Blueprint); 436 | 437 | // Update old composite nodes(can't do this in PostLoad) 438 | FBlueprintEditorUtils::UpdateOutOfDateCompositeNodes(Blueprint); 439 | 440 | // Update any nodes which might have dropped their RF_Transactional flag due to copy-n-paste issues 441 | FBlueprintEditorUtils::UpdateTransactionalFlags(Blueprint); 442 | } 443 | }; 444 | 445 | 446 | ////////////////////////////////////////////////////////////////////////// 447 | // FBlueprintRetargetContentBrowserExtensions_Impl 448 | 449 | class FBlueprintRetargetContentBrowserExtensions_Impl 450 | { 451 | public: 452 | static void ExecuteSelectedContentFunctor(TSharedPtr SelectedAssetFunctor) 453 | { 454 | SelectedAssetFunctor->Execute(); 455 | } 456 | 457 | static void CreateSubMenu(FMenuBuilder& MenuBuilder, TArray SelectedAssets) 458 | { 459 | TSharedPtr ICreatorFunctor = MakeShareable(new FRetargetClassExtension()); 460 | ICreatorFunctor->SelectedAssets = SelectedAssets; 461 | 462 | FUIAction Action_RetargetClass(FExecuteAction::CreateStatic( 463 | &FBlueprintRetargetContentBrowserExtensions_Impl::ExecuteSelectedContentFunctor, 464 | StaticCastSharedPtr(ICreatorFunctor) 465 | )); 466 | 467 | MenuBuilder.AddMenuEntry( 468 | LOCTEXT("RetargetClass", "Retarget invalid parent"), 469 | LOCTEXT("RetargetClass_Tooltip", "Reparents a blueprint's parent class (Useful when parent class is missing or invalid)"), 470 | FSlateIcon(FEditorStyle::GetStyleSetName(), "ClassIcon.Note"), 471 | Action_RetargetClass, 472 | NAME_None, 473 | EUserInterfaceActionType::Button); 474 | } 475 | 476 | static TSharedRef OnExtendContentBrowserAssetSelectionMenu(const TArray& SelectedAssets) 477 | { 478 | // Run through the assets to determine if any meet our criteria 479 | bool bAllInvalidBlueprint = SelectedAssets.Num() > 0; 480 | for (auto AssetIt = SelectedAssets.CreateConstIterator(); AssetIt; ++AssetIt) 481 | { 482 | bAllInvalidBlueprint &= IsInvalidBlueprint(Cast(AssetIt->GetAsset())); 483 | } 484 | 485 | TSharedRef Extender(new FExtender()); 486 | 487 | if (bAllInvalidBlueprint) 488 | { 489 | // Add the sprite actions sub-menu extender 490 | Extender->AddMenuExtension( 491 | "GetAssetActions", 492 | EExtensionHook::After, 493 | nullptr, 494 | FMenuExtensionDelegate::CreateStatic(&FBlueprintRetargetContentBrowserExtensions_Impl::CreateSubMenu, SelectedAssets)); 495 | } 496 | 497 | return Extender; 498 | } 499 | 500 | static TArray& GetExtenderDelegates() 501 | { 502 | FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked(TEXT("ContentBrowser")); 503 | return ContentBrowserModule.GetAllAssetViewContextMenuExtenders(); 504 | } 505 | 506 | static bool IsInvalidBlueprint(const TAssetPtr& BP) { 507 | return BP && (!BP->SkeletonGeneratedClass || !BP->GeneratedClass); 508 | } 509 | }; 510 | 511 | 512 | ////////////////////////////////////////////////////////////////////////// 513 | // FBlueprintRetargetContentBrowserExtensions 514 | 515 | void FBlueprintRetargetContentBrowserExtensions::InstallHooks() 516 | { 517 | ContentBrowserExtenderDelegate = FContentBrowserMenuExtender_SelectedAssets::CreateStatic(&FBlueprintRetargetContentBrowserExtensions_Impl::OnExtendContentBrowserAssetSelectionMenu); 518 | 519 | TArray& CBMenuExtenderDelegates = FBlueprintRetargetContentBrowserExtensions_Impl::GetExtenderDelegates(); 520 | CBMenuExtenderDelegates.Add(ContentBrowserExtenderDelegate); 521 | ContentBrowserExtenderDelegateHandle = CBMenuExtenderDelegates.Last().GetHandle(); 522 | } 523 | 524 | void FBlueprintRetargetContentBrowserExtensions::RemoveHooks() 525 | { 526 | TArray& CBMenuExtenderDelegates = FBlueprintRetargetContentBrowserExtensions_Impl::GetExtenderDelegates(); 527 | CBMenuExtenderDelegates.RemoveAll([](const FContentBrowserMenuExtender_SelectedAssets& Delegate) { return Delegate.GetHandle() == ContentBrowserExtenderDelegateHandle; }); 528 | } 529 | 530 | ////////////////////////////////////////////////////////////////////////// 531 | 532 | #undef LOCTEXT_NAMESPACE 533 | -------------------------------------------------------------------------------- /Source/BlueprintRetarget/Private/ContentBrowserExtensions.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2020 Piperift. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | // Integrate Paper2D actions associated with existing engine types (e.g., Texture2D) into the content browser 6 | class FBlueprintRetargetContentBrowserExtensions 7 | { 8 | public: 9 | static void InstallHooks(); 10 | static void RemoveHooks(); 11 | }; -------------------------------------------------------------------------------- /Source/BlueprintRetarget/Public/BlueprintRetarget.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2020 Piperift. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "CoreMinimal.h" 6 | #include "Modules/ModuleManager.h" 7 | 8 | 9 | DECLARE_LOG_CATEGORY_EXTERN(LogBlueprintReparent, All, All); 10 | 11 | class FToolBarBuilder; 12 | class FMenuBuilder; 13 | 14 | class FBlueprintRetargetModule : public IModuleInterface 15 | { 16 | public: 17 | 18 | /** IModuleInterface implementation */ 19 | virtual void StartupModule() override; 20 | virtual void ShutdownModule() override; 21 | }; 22 | --------------------------------------------------------------------------------