/** * Marks/Unmarks the package's bDirty flag */ void UPackage::SetDirtyFlag( bool bIsDirty ) { if ( GetOutermost() != GetTransientPackage() ) { if ( GUndo != NULL // PIE world objects should never end up in the transaction buffer as we cannot undo during gameplay. && !(GetOutermost()->PackageFlags & (PKG_PlayInEditor|PKG_ContainsScript)) ) { // make sure we're marked as transactional SetFlags(RF_Transactional); // don't call Modify() since it calls SetDirtyFlag() GUndo->SaveObject( this ); } // Update dirty bit bDirty = bIsDirty; if( GIsEditor // Only fire the callback in editor mode && !(PackageFlags & PKG_ContainsScript) // Skip script packages && !(PackageFlags & PKG_PlayInEditor) // Skip packages for PIE && GetTransientPackage() != this ) // Skip the transient package { // Package is changing dirty state, let the editor know so we may prompt for source control checkout PackageDirtyStateChangedEvent.Broadcast(this); } } }
void FMediaTextureActions::ExecuteCreateMaterial( TArray<TWeakObjectPtr<UTexture>> Objects ) { IContentBrowserSingleton& ContentBrowserSingleton = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser").Get(); const FString DefaultSuffix = TEXT("_Mat"); if (Objects.Num() == 1) { auto Object = Objects[0].Get(); if (Object != nullptr) { // Determine an appropriate name FString Name; FString PackagePath; CreateUniqueAssetName(Object->GetOutermost()->GetName(), DefaultSuffix, PackagePath, Name); // Create the factory used to generate the asset UMaterialFactoryNew* Factory = NewObject<UMaterialFactoryNew>(); Factory->InitialTexture = Object; ContentBrowserSingleton.CreateNewAsset(Name, FPackageName::GetLongPackagePath(PackagePath), UMaterial::StaticClass(), Factory); } } else { TArray<UObject*> ObjectsToSync; for (auto ObjIt = Objects.CreateConstIterator(); ObjIt; ++ObjIt) { auto Object = (*ObjIt).Get(); if (Object != nullptr) { FString Name; FString PackageName; CreateUniqueAssetName(Object->GetOutermost()->GetName(), DefaultSuffix, PackageName, Name); // Create the factory used to generate the asset UMaterialFactoryNew* Factory = NewObject<UMaterialFactoryNew>(); Factory->InitialTexture = Object; FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools"); UObject* NewAsset = AssetToolsModule.Get().CreateAsset(Name, FPackageName::GetLongPackagePath(PackageName), UMaterial::StaticClass(), Factory); if (NewAsset != nullptr) { ObjectsToSync.Add(NewAsset); } } } if (ObjectsToSync.Num() > 0) { ContentBrowserSingleton.SyncBrowserToAssets(ObjectsToSync); } } }
void FAssetTypeActions_SoundWave::ExecuteCreateSoundCue(TArray<TWeakObjectPtr<USoundWave>> Objects) { const FString DefaultSuffix = TEXT("_Cue"); if ( Objects.Num() == 1 ) { auto Object = Objects[0].Get(); if ( Object ) { // Determine an appropriate name FString Name; FString PackagePath; CreateUniqueAssetName(Object->GetOutermost()->GetName(), DefaultSuffix, PackagePath, Name); // Create the factory used to generate the asset USoundCueFactoryNew* Factory = ConstructObject<USoundCueFactoryNew>(USoundCueFactoryNew::StaticClass()); Factory->InitialSoundWave = Object; FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser"); ContentBrowserModule.Get().CreateNewAsset(Name, FPackageName::GetLongPackagePath(PackagePath), USoundCue::StaticClass(), Factory); } } else { TArray<UObject*> ObjectsToSync; for (auto ObjIt = Objects.CreateConstIterator(); ObjIt; ++ObjIt) { auto Object = (*ObjIt).Get(); if ( Object ) { FString Name; FString PackageName; CreateUniqueAssetName(Object->GetOutermost()->GetName(), DefaultSuffix, PackageName, Name); // Create the factory used to generate the asset USoundCueFactoryNew* Factory = ConstructObject<USoundCueFactoryNew>(USoundCueFactoryNew::StaticClass()); Factory->InitialSoundWave = Object; FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools"); UObject* NewAsset = AssetToolsModule.Get().CreateAsset(Name, FPackageName::GetLongPackagePath(PackageName), USoundCue::StaticClass(), Factory); if ( NewAsset ) { ObjectsToSync.Add(NewAsset); } } } if ( ObjectsToSync.Num() > 0 ) { FAssetTools::Get().SyncBrowserToAssets(ObjectsToSync); } } }
void ULevelStreaming::Serialize( FArchive& Ar ) { Super::Serialize(Ar); if (Ar.IsLoading()) { #if WITH_EDITOR if (GetOutermost()->HasAnyPackageFlags(PKG_PlayInEditor) && GetOutermost()->PIEInstanceID != INDEX_NONE) { RenameForPIE(GetOutermost()->PIEInstanceID); } #endif } }
void USoundWave::PostLoad() { Super::PostLoad(); if (GetOutermost()->HasAnyPackageFlags(PKG_ReloadingForCooker)) { return; } // Compress to whatever formats the active target platforms want // static here as an optimization ITargetPlatformManagerModule* TPM = GetTargetPlatformManager(); if (TPM) { const TArray<ITargetPlatform*>& Platforms = TPM->GetActiveTargetPlatforms(); for (int32 Index = 0; Index < Platforms.Num(); Index++) { GetCompressedData(Platforms[Index]->GetWaveFormat(this)); } } // We don't precache default objects and we don't precache in the Editor as the latter will // most likely cause us to run out of memory. if (!GIsEditor && !IsTemplate( RF_ClassDefaultObject ) && GEngine) { FAudioDevice* AudioDevice = GEngine->GetMainAudioDevice(); if (AudioDevice && AudioDevice->AreStartupSoundsPreCached()) { // Upload the data to the hardware, but only if we've precached startup sounds already AudioDevice->Precache(this); } // remove bulk data if no AudioDevice is used and no sounds were initialized else if(IsRunningGame()) { RawData.RemoveBulkData(); } } // Only add this streaming sound if we're not a dedicated server or if there is an audio device manager if (IsStreaming() && !IsRunningDedicatedServer() && GEngine && GEngine->GetAudioDeviceManager()) { #if WITH_EDITORONLY_DATA FinishCachePlatformData(); #endif // #if WITH_EDITORONLY_DATA IStreamingManager::Get().GetAudioStreamingManager().AddStreamingSoundWave(this); } #if WITH_EDITORONLY_DATA if (!SourceFilePath_DEPRECATED.IsEmpty() && AssetImportData) { FAssetImportInfo Info; Info.Insert(FAssetImportInfo::FSourceFile(SourceFilePath_DEPRECATED)); AssetImportData->SourceData = MoveTemp(Info); } #endif // #if WITH_EDITORONLY_DATA INC_FLOAT_STAT_BY( STAT_AudioBufferTime, Duration ); INC_FLOAT_STAT_BY( STAT_AudioBufferTimeChannels, NumChannels * Duration ); }
FAISenseID UAISense_Blueprint::UpdateSenseID() { #if WITH_EDITOR // ignore skeleton and "old version"-classes if (FKismetEditorUtilities::IsClassABlueprintSkeleton(GetClass()) || GetClass()->HasAnyClassFlags(CLASS_NewerVersionExists) || (GetOutermost() == GetTransientPackage())) { return FAISenseID::InvalidID(); } #endif if (GetClass()->HasAnyClassFlags(CLASS_Abstract) == false) { const NAME_INDEX NameIndex = GetClass()->GetFName().GetDisplayIndex(); const FAISenseID* StoredID = BPSenseToSenseID.Find(NameIndex); if (StoredID != nullptr) { ForceSenseID(*StoredID); } else { const FAISenseID NewSenseID = FAISenseID(GetFName()); ForceSenseID(NewSenseID); BPSenseToSenseID.Add(NameIndex, GetSenseID()); } } return GetSenseID(); }
FPrimaryAssetId AAFCueActor::GetPrimaryAssetId() const { FName dupa1 = FPackageName::GetShortFName(GetOutermost()->GetFName()); const AAFCueActor* A = this; return FPrimaryAssetId(FPrimaryAssetType("ActorCue"), dupa1); //if (HasAnyFlags(RF_ClassDefaultObject)) { UClass* SearchNativeClass = GetClass(); while (SearchNativeClass && !SearchNativeClass->HasAnyClassFlags(CLASS_Native | CLASS_Intrinsic)) { SearchNativeClass = SearchNativeClass->GetSuperClass(); } if (SearchNativeClass && SearchNativeClass != GetClass()) { // If blueprint, return native class and asset name } // Native CDO, return nothing return FPrimaryAssetId(); } // Data assets use Class and ShortName by default, there's no inheritance so class works fine //return FPrimaryAssetId(GetClass()->GetFName(), GetFName()); }
int32 UObjectBaseUtility::GetLinkerCustomVersion(FGuid CustomVersionKey) const { ULinkerLoad* Loader = GetLinker(); // No linker. if( Loader == NULL ) { // the _Linker reference is never set for the top-most UPackage of a package (the linker root), so if this object // is the linker root, find our loader in the global list. if( GetOutermost() == this ) { Loader = ULinkerLoad::FindExistingLinkerForPackage(const_cast<UPackage*>(CastChecked<UPackage>((const UObject*)this))); } } if ( Loader != NULL ) { // We have a linker so we can return its version. auto* CustomVersion = Loader->Summary.GetCustomVersionContainer().GetVersion(CustomVersionKey); return CustomVersion ? CustomVersion->Version : -1; } // We don't have a linker associated as we e.g. might have been saved or had loaders reset, ... // We must have a current version for this tag. auto* CustomVersion = FCustomVersionContainer::GetRegistered().GetVersion(CustomVersionKey); check(CustomVersion); return CustomVersion->Version; }
void AWorldSettings::EnabledWorldComposition(bool bEnable) { bEnableWorldComposition = false; if (!bEnable) { if (GetWorld()->WorldComposition != nullptr) { GetWorld()->WorldComposition = nullptr; GetWorld()->StreamingLevels.Empty(); GetWorld()->FlushLevelStreaming(); UWorldComposition::OnWorldCompositionDestroyed.Broadcast(GetWorld()); } } else { FString RootPackageName = GetOutermost()->GetName(); if (GetWorld()->WorldComposition == nullptr && FPackageName::DoesPackageExist(RootPackageName)) { GetWorld()->StreamingLevels.Empty(); GetWorld()->FlushLevelStreaming(); GetWorld()->WorldComposition = ConstructObject<UWorldComposition>(UWorldComposition::StaticClass(), GetWorld()); bEnableWorldComposition = true; UWorldComposition::OnWorldCompositionCreated.Broadcast(GetWorld()); } } }
/** * Returns the licensee version of the linker for this object. * * @return the licensee version of the engine's package file when this object * was last saved, or GPackageFileLicenseeVersion (current version) if * this object does not have a linker, which indicates that * a) this object is a native only class, or * b) this object's linker has been detached, in which case it is already fully loaded */ int32 UObjectBaseUtility::GetLinkerLicenseeUE4Version() const { ULinkerLoad* Loader = GetLinker(); // No linker. if( Loader == NULL ) { // the _Linker reference is never set for the top-most UPackage of a package (the linker root), so if this object // is the linker root, find our loader in the global list. if( GetOutermost() == this ) { Loader = ULinkerLoad::FindExistingLinkerForPackage(const_cast<UPackage*>(CastChecked<UPackage>((const UObject*)this))); } } if ( Loader != NULL ) { // We have a linker so we can return its version. return Loader->LicenseeUE4Ver(); } else { // We don't have a linker associated as we e.g. might have been saved or had loaders reset, ... return GPackageFileLicenseeUE4Version; } }
void UWorldComposition::ReinitializeForPIE() { Rescan(); #if WITH_EDITOR FixupForPIE(GetOutermost()->PIEInstanceID); #endif// WITH_EDITOR GetWorld()->StreamingLevels.Empty(); GetWorld()->StreamingLevels.Append(TilesStreaming); }
void ACharacter::ClearCrossLevelReferences() { if( BasedMovement.MovementBase != NULL && GetOutermost() != BasedMovement.MovementBase->GetOutermost() ) { SetBase( NULL ); } Super::ClearCrossLevelReferences(); }
void UWorldComposition::PostInitProperties() { Super::PostInitProperties(); if (!IsTemplate() && !GetOutermost()->HasAnyPackageFlags(PKG_PlayInEditor)) { // Tiles information is not serialized to disk, and should be regenerated on world composition object construction Rescan(); } }
void UWorldComposition::PostDuplicate(bool bDuplicateForPIE) { Super::PostDuplicate(bDuplicateForPIE); #if WITH_EDITOR if (bDuplicateForPIE) { FixupForPIE(GetOutermost()->PIEInstanceID); } #endif // WITH_EDITOR }
void USoundWave::PostLoad() { Super::PostLoad(); if (GetOutermost()->PackageFlags & PKG_ReloadingForCooker) { return; } // Compress to whatever formats the active target platforms want // static here as an optimization ITargetPlatformManagerModule* TPM = GetTargetPlatformManager(); if (TPM) { const TArray<ITargetPlatform*>& Platforms = TPM->GetActiveTargetPlatforms(); for (int32 Index = 0; Index < Platforms.Num(); Index++) { GetCompressedData(Platforms[Index]->GetWaveFormat(this)); } } // We don't precache default objects and we don't precache in the Editor as the latter will // most likely cause us to run out of memory. if( !GIsEditor && !IsTemplate( RF_ClassDefaultObject ) && GEngine ) { FAudioDevice* AudioDevice = GEngine->GetAudioDevice(); if( AudioDevice && AudioDevice->bStartupSoundsPreCached) { // Upload the data to the hardware, but only if we've precached startup sounds already AudioDevice->Precache( this ); } // remove bulk data if no AudioDevice is used and no sounds were initialized else if( IsRunningGame() ) { RawData.RemoveBulkData(); } } if (IsStreaming()) { #if WITH_EDITORONLY_DATA FinishCachePlatformData(); #endif // #if WITH_EDITORONLY_DATA IStreamingManager::Get().GetAudioStreamingManager().AddStreamingSoundWave(this); } INC_FLOAT_STAT_BY( STAT_AudioBufferTime, Duration ); INC_FLOAT_STAT_BY( STAT_AudioBufferTimeChannels, NumChannels * Duration ); }
void AGameModeBase::ProcessServerTravel(const FString& URL, bool bAbsolute) { #if WITH_SERVER_CODE StartToLeaveMap(); // Force an old style load screen if the server has been up for a long time so that TimeSeconds doesn't overflow and break everything bool bSeamless = (bUseSeamlessTravel && GetWorld()->TimeSeconds < 172800.0f); // 172800 seconds == 48 hours FString NextMap; if (URL.ToUpper().Contains(TEXT("?RESTART"))) { NextMap = UWorld::RemovePIEPrefix(GetOutermost()->GetName()); } else { int32 OptionStart = URL.Find(TEXT("?")); if (OptionStart == INDEX_NONE) { NextMap = URL; } else { NextMap = URL.Left(OptionStart); } } FGuid NextMapGuid = UEngine::GetPackageGuid(FName(*NextMap), GetWorld()->IsPlayInEditor()); // Notify clients we're switching level and give them time to receive. FString URLMod = URL; APlayerController* LocalPlayer = ProcessClientTravel(URLMod, NextMapGuid, bSeamless, bAbsolute); UE_LOG(LogGameMode, Log, TEXT("ProcessServerTravel: %s"), *URL); UWorld* World = GetWorld(); check(World); World->NextURL = URL; ENetMode NetMode = GetNetMode(); if (bSeamless) { World->SeamlessTravel(World->NextURL, bAbsolute); World->NextURL = TEXT(""); } // Switch immediately if not networking. else if (NetMode != NM_DedicatedServer && NetMode != NM_ListenServer) { World->NextSwitchCountdown = 0.0f; } #endif // WITH_SERVER_CODE }
void ULevelStreaming::PostLoad() { Super::PostLoad(); const bool PIESession = GetWorld()->WorldType == EWorldType::PIE || GetOutermost()->HasAnyPackageFlags(PKG_PlayInEditor); // If this streaming level was saved with a short package name, try to convert it to a long package name if ( !PIESession && PackageName_DEPRECATED != NAME_None ) { const FString DeprecatedPackageNameString = PackageName_DEPRECATED.ToString(); if ( FPackageName::IsShortPackageName(PackageName_DEPRECATED) == false ) { // Convert the FName reference to a TAssetPtr, then broadcast that we loaded a reference // so this reference is gathered by the cooker without having to resave the package. SetWorldAssetByPackageName(PackageName_DEPRECATED); FCoreUObjectDelegates::StringAssetReferenceLoaded.ExecuteIfBound(WorldAsset.ToStringReference().ToString()); } else { UE_LOG(LogLevelStreaming, Display, TEXT("Invalid streaming level package name (%s). Only long package names are supported. This streaming level may not load or save properly."), *DeprecatedPackageNameString); } } if ( !PIESession && !WorldAsset.IsNull() ) { const FString WorldPackageName = GetWorldAssetPackageName(); if (FPackageName::DoesPackageExist(WorldPackageName) == false) { UE_LOG(LogLevelStreaming, Display, TEXT("Failed to find streaming level package file: %s. This streaming level may not load or save properly."), *WorldPackageName); #if WITH_EDITOR if (GIsEditor) { // Launch notification to inform user of default change FFormatNamedArguments Args; Args.Add(TEXT("PackageName"), FText::FromString(WorldPackageName)); FNotificationInfo Info(FText::Format(LOCTEXT("LevelStreamingFailToStreamLevel", "Failed to find streamed level {PackageName}, please fix the reference to it in the Level Browser"), Args)); Info.ExpireDuration = 7.0f; FSlateNotificationManager::Get().AddNotification(Info); } #endif // WITH_EDITOR } } if (GetLinkerUE4Version() < VER_UE4_LEVEL_STREAMING_DRAW_COLOR_TYPE_CHANGE) { LevelColor = DrawColor_DEPRECATED; } }
/** * Finds the outermost package and marks it dirty */ bool UObjectBaseUtility::MarkPackageDirty() const { // since transient objects will never be saved into a package, there is no need to mark a package dirty // if we're transient if ( !HasAnyFlags(RF_Transient) ) { UPackage* Package = GetOutermost(); if( Package != NULL ) { // It is against policy to dirty a map or package during load in the Editor, to enforce this policy // we explicitly disable the ability to dirty a package or map during load. Commandlets can still // set the dirty state on load. if( IsRunningCommandlet() || (GIsEditor && !GIsEditorLoadingPackage && !GIsPlayInEditorWorld && !IsInAsyncLoadingThread() #if WITH_HOT_RELOAD && !GIsHotReload #endif // WITH_HOT_RELOAD #if WITH_EDITORONLY_DATA && !Package->bIsCookedForEditor // Cooked packages can't be modified nor marked as dirty #endif )) { const bool bIsDirty = Package->IsDirty(); // We prevent needless re-dirtying as this can be an expensive operation. if( !bIsDirty ) { Package->SetDirtyFlag(true); } // Always call PackageMarkedDirtyEvent, even when the package is already dirty Package->PackageMarkedDirtyEvent.Broadcast(Package, bIsDirty); return true; } else { // notify the caller that the request to mark the package as dirty was suppressed return false; } } } return true; }
void USoundClassGraph::RebuildGraph() { check(RootSoundClass); // Don't allow initial graph rebuild to affect package dirty state; remember current state... UPackage* Package = GetOutermost(); const bool bIsDirty = Package->IsDirty(); Modify(); RemoveAllNodes(); ConstructNodes(RootSoundClass, 0, 0); NotifyGraphChanged(); // ...and restore it Package->SetDirtyFlag(bIsDirty); }
void FAssetEditorToolkit::SaveAsset_Execute() { if( ensure( EditingObjects.Num() > 0 ) ) { TArray< UPackage* > PackagesToSave; for( auto ObjectIter = EditingObjects.CreateConstIterator(); ObjectIter; ++ObjectIter ) { // Don't allow user to perform certain actions on objects that aren't actually assets (e.g. Level Script blueprint objects) const auto EditingObject = *ObjectIter; if( EditingObject != NULL && EditingObject->IsAsset() ) { PackagesToSave.Add( EditingObject->GetOutermost() ); } } FEditorFileUtils::PromptForCheckoutAndSave( PackagesToSave, bCheckDirtyOnAssetSave, /*bPromptToSave=*/ false ); } }
EVisibility SLevelEditorActiveToolkit::GetVisibilityForUnsavedChangeIcon() const { bool bShowUnsavedChangeIcon = false; const bool bIsAssetEditorToolkit = ActiveToolkitType == ELevelEditorActiveToolkit::Toolkit && Toolkit->IsAssetEditor(); if( bIsAssetEditorToolkit ) { const TSharedRef< FAssetEditorToolkit >& AssetEditorToolkit = StaticCastSharedRef< FAssetEditorToolkit >( Toolkit.ToSharedRef() ); const TArray< UObject* >& Assets = *AssetEditorToolkit->GetObjectsCurrentlyBeingEdited(); for( int AssetIndex = 0; !bShowUnsavedChangeIcon && AssetIndex < Assets.Num(); ++AssetIndex ) { const auto Asset = Assets[ AssetIndex ]; if( Asset != NULL ) { bShowUnsavedChangeIcon = Asset->GetOutermost()->IsDirty(); } } } return bShowUnsavedChangeIcon ? EVisibility::Visible : EVisibility::Collapsed; }
void UAnimSet::PostLoad() { Super::PostLoad(); #if WITH_EDITORONLY_DATA // Make sure that AnimSets (and sequences) within level packages are not marked as standalone. if(GetOutermost()->ContainsMap() && HasAnyFlags(RF_Standalone)) { ClearFlags(RF_Standalone); for(int32 i=0; i<Sequences.Num(); i++) { UAnimSequence* Seq = Sequences[i]; if(Seq) { Seq->ClearFlags(RF_Standalone); } } } #endif //#if WITH_EDITORONLY_DATA }
FString UAssetImportData::SanitizeImportFilename(const FString& InPath) const { const UPackage* Package = GetOutermost(); if (Package) { const bool bIncludeDot = true; const FString PackagePath = Package->GetPathName(); const FName MountPoint = FPackageName::GetPackageMountPoint(PackagePath); const FString PackageFilename = FPackageName::LongPackageNameToFilename(PackagePath, FPaths::GetExtension(InPath, bIncludeDot)); const FString AbsolutePath = FPaths::ConvertRelativePathToFull(InPath); if ((MountPoint == FName("Engine") && AbsolutePath.StartsWith(FPaths::ConvertRelativePathToFull(FPaths::EngineContentDir()))) || (MountPoint == FName("Game") && AbsolutePath.StartsWith(FPaths::ConvertRelativePathToFull(FPaths::GameDir())))) { FString RelativePath = InPath; FPaths::MakePathRelativeTo(RelativePath, *PackageFilename); return RelativePath; } } return IFileManager::Get().ConvertToRelativePath(*InPath); }
/** * Finds the outermost package and marks it dirty */ void UObjectBaseUtility::MarkPackageDirty() const { // since transient objects will never be saved into a package, there is no need to mark a package dirty // if we're transient if ( !HasAnyFlags(RF_Transient) ) { UPackage* Package = GetOutermost(); if( Package != NULL ) { // It is against policy to dirty a map or package during load in the Editor, to enforce this policy // we explicitly disable the ability to dirty a package or map during load. Commandlets can still // set the dirty state on load. // We also prevent needless re-dirtying as this can be an expensive operation. if( !Package->IsDirty() && (!GIsEditor || IsRunningCommandlet() || (GIsEditor && !GIsEditorLoadingPackage))) { Package->SetDirtyFlag(true); } } } }
void FAssetTypeActions_Blueprint::ExecuteNewDerivedBlueprint(TWeakObjectPtr<UBlueprint> InObject) { auto Object = InObject.Get(); if ( Object ) { // The menu option should ONLY be available if there is only one blueprint selected, validated by the menu creation code UBlueprint* TargetBP = Object; UClass* TargetClass = TargetBP->GeneratedClass; if(!FKismetEditorUtilities::CanCreateBlueprintOfClass(TargetClass)) { FMessageDialog::Open( EAppMsgType::Ok, LOCTEXT("InvalidClassToMakeBlueprintFrom", "Invalid class with which to make a Blueprint.")); return; } FString Name; FString PackageName; CreateUniqueAssetName(Object->GetOutermost()->GetName(), TEXT("_Child"), PackageName, Name); UPackage* Package = CreatePackage(NULL, *PackageName); if ( ensure(Package) ) { // Create and init a new Blueprint UBlueprint* NewBP = FKismetEditorUtilities::CreateBlueprint(TargetClass, Package, FName(*Name), BPTYPE_Normal, UBlueprint::StaticClass()); if(NewBP) { FAssetEditorManager::Get().OpenEditorForAsset(NewBP); // Notify the asset registry FAssetRegistryModule::AssetCreated(NewBP); // Mark the package dirty... Package->MarkPackageDirty(); } } } }
void FAssetTypeActions_World::OpenAssetEditor( const TArray<UObject*>& InObjects, TSharedPtr<class IToolkitHost> EditWithinLevelEditor ) { for (auto ObjIt = InObjects.CreateConstIterator(); ObjIt; ++ObjIt) { auto World = Cast<UWorld>(*ObjIt); if (World != NULL) { // If there are any unsaved changes to the current level, see if the user wants to save those first. bool bPromptUserToSave = true; bool bSaveMapPackages = true; bool bSaveContentPackages = true; if (FEditorFileUtils::SaveDirtyPackages(bPromptUserToSave, bSaveMapPackages, bSaveContentPackages)) { const FString FileToOpen = FPackageName::LongPackageNameToFilename(World->GetOutermost()->GetName(), FPackageName::GetMapPackageExtension()); const bool bLoadAsTemplate = false; const bool bShowProgress = true; FEditorFileUtils::LoadMap(FileToOpen, bLoadAsTemplate, bShowProgress); } // We can only edit one world at a time... so just break after the first valid world to load break; } } }
void FAssetTypeActions_TextureRenderTarget::ExecuteCreateStatic(TArray<TWeakObjectPtr<UTextureRenderTarget>> Objects) { for (auto ObjIt = Objects.CreateConstIterator(); ObjIt; ++ObjIt) { auto Object = (*ObjIt).Get(); if ( Object ) { FString Name; FString PackageName; CreateUniqueAssetName(Object->GetOutermost()->GetName(), TEXT("_Tex"), PackageName, Name); UObject* NewObj = NULL; UTextureRenderTarget2D* TexRT = Cast<UTextureRenderTarget2D>(Object); UTextureRenderTargetCube* TexRTCube = Cast<UTextureRenderTargetCube>(Object); if( TexRTCube ) { // create a static cube texture as well as its 6 faces NewObj = TexRTCube->ConstructTextureCube( CreatePackage(NULL,*PackageName), Name, Object->GetMaskedFlags() ); } else if( TexRT ) { // create a static 2d texture NewObj = TexRT->ConstructTexture2D( CreatePackage(NULL,*PackageName), Name, Object->GetMaskedFlags(), CTF_Default, NULL ); } if( NewObj ) { // package needs saving NewObj->MarkPackageDirty(); // Notify the asset registry FAssetRegistryModule::AssetCreated(NewObj); } } } }
/** * Walks up the chain of packages until it reaches the top level, which it ignores. * * @param bStartWithOuter whether to include this object's name in the returned string * @return string containing the path name for this object, minus the outermost-package's name */ FString UObjectBaseUtility::GetFullGroupName( bool bStartWithOuter ) const { const UObjectBaseUtility* Obj = bStartWithOuter ? GetOuter() : this; return Obj ? Obj->GetPathName(GetOutermost()) : TEXT(""); }
/** * Checks whether this object's top-most package has any of the specified flags * * @param CheckFlagMask a bitmask of EPackageFlags values to check for * * @return true if the PackageFlags member of this object's top-package has any bits from the mask set. */ bool UObjectBaseUtility::RootPackageHasAnyFlags( uint32 CheckFlagMask ) const { return GetOutermost()->HasAnyPackageFlags(CheckFlagMask); }
static void AddStaticFunctionsForDependencies(FEmitterLocalContext& Context) { auto SourceClass = Context.GetCurrentlyGeneratedClass(); auto OriginalClass = Context.Dependencies.FindOriginalClass(SourceClass); const FString CppClassName = FEmitHelper::GetCppName(OriginalClass); // __StaticDependenciesAssets Context.AddLine(FString::Printf(TEXT("void %s::__StaticDependenciesAssets(TArray<FBlueprintDependencyData>& AssetsToLoad)"), *CppClassName)); Context.AddLine(TEXT("{")); Context.IncreaseIndent(); auto CreateAssetToLoadString = [&](const UObject* AssetObj) -> FString { UClass* AssetType = AssetObj->GetClass(); if (AssetType->IsChildOf<UUserDefinedEnum>()) { AssetType = UEnum::StaticClass(); } else if (AssetType->IsChildOf<UUserDefinedStruct>()) { AssetType = UScriptStruct::StaticClass(); } else if (AssetType->IsChildOf<UBlueprintGeneratedClass>() && Context.Dependencies.WillClassBeConverted(CastChecked<UBlueprintGeneratedClass>(AssetObj))) { AssetType = UDynamicClass::StaticClass(); } return FString::Printf(TEXT("AssetsToLoad.Add({FName(TEXT(\"%s\")), FName(TEXT(\"%s\")), FName(TEXT(\"%s\")), FName(TEXT(\"%s\"))});") , *AssetObj->GetOutermost()->GetPathName() , *AssetObj->GetName() , *AssetType->GetOutermost()->GetPathName() , *AssetType->GetName()); }; for (UObject* LocAsset : Context.Dependencies.Assets) { Context.AddLine(CreateAssetToLoadString(LocAsset)); } for (UObject* LocAsset : Context.Dependencies.ConvertedClasses) { if (!Context.Dependencies.Assets.Contains(LocAsset)) { Context.AddLine(CreateAssetToLoadString(LocAsset)); } } Context.DecreaseIndent(); Context.AddLine(TEXT("}")); // Register Helper Struct const FString RegisterHelperName = FString::Printf(TEXT("FRegisterHelper__%s"), *CppClassName); Context.AddLine(FString::Printf(TEXT("struct %s"), *RegisterHelperName)); Context.AddLine(TEXT("{")); Context.IncreaseIndent(); Context.AddLine(FString::Printf(TEXT("%s()"), *RegisterHelperName)); Context.AddLine(TEXT("{")); Context.IncreaseIndent(); Context.AddLine(FString::Printf( TEXT("FConvertedBlueprintsDependencies::Get().RegisterClass(TEXT(\"%s\"), &%s::__StaticDependenciesAssets);") , *OriginalClass->GetOutermost()->GetPathName() , *CppClassName)); Context.DecreaseIndent(); Context.AddLine(TEXT("}")); Context.AddLine(FString::Printf(TEXT("static %s Instance;"), *RegisterHelperName)); Context.DecreaseIndent(); Context.AddLine(TEXT("};")); Context.AddLine(FString::Printf(TEXT("%s %s::Instance;"), *RegisterHelperName, *RegisterHelperName)); }