UObject* USlateWidgetStyleAssetFactory::FactoryCreateNew(UClass* Class,UObject* InParent,FName Name,EObjectFlags Flags,UObject* Context,FFeedbackContext* Warn) { USlateWidgetStyleAsset* NewUSlateStyle = CastChecked<USlateWidgetStyleAsset>(StaticConstructObject(USlateWidgetStyleAsset::StaticClass(), InParent, Name, Flags)); //intialize NewUSlateStyle->CustomStyle = CastChecked< USlateWidgetStyleContainerBase >( StaticConstructObject(StyleType, NewUSlateStyle, Name) ); return NewUSlateStyle; }
void FTexAlignTools::Init() { // Create the list of aligners. Aligners.Empty(); Aligners.Add( CastChecked<UTexAligner>(StaticConstructObject(UTexAlignerDefault::StaticClass(),GetTransientPackage(),NAME_None,RF_Public|RF_RootSet|RF_Standalone) ) ); Aligners.Add( CastChecked<UTexAligner>(StaticConstructObject(UTexAlignerPlanar::StaticClass(),GetTransientPackage(),NAME_None,RF_Public|RF_RootSet|RF_Standalone) ) ); Aligners.Add( CastChecked<UTexAligner>(StaticConstructObject(UTexAlignerBox::StaticClass(),GetTransientPackage(),NAME_None,RF_Public|RF_RootSet|RF_Standalone) ) ); Aligners.Add( CastChecked<UTexAligner>(StaticConstructObject(UTexAlignerFit::StaticClass(),GetTransientPackage(),NAME_None,RF_Public|RF_RootSet|RF_Standalone) ) ); FEditorDelegates::FitTextureToSurface.AddRaw(this, &FTexAlignTools::OnEditorFitTextureToSurface); }
UObject* USQLiteBlueprintFunctionLibrary::NewObjectFromBlueprint(UObject* WorldContextObject, TSubclassOf<UObject> UC) { UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject); UObject* tempObject = StaticConstructObject(UC); return tempObject; }
void FWorldTileModel::AddStreamingLevel(UClass* InStreamingClass, const FName& InPackageName) { if (LevelCollectionModel.IsReadOnly() || !IsEditable() || IsRootTile()) { return; } UWorld* LevelWorld = CastChecked<UWorld>(GetLevelObject()->GetOuter()); // check uniqueness if (LevelWorld->StreamingLevels.FindMatch(ULevelStreaming::FPackageNameMatcher(InPackageName)) != INDEX_NONE) { return; } ULevelStreaming* StreamingLevel = static_cast<ULevelStreaming*>(StaticConstructObject(InStreamingClass, LevelWorld, NAME_None, RF_NoFlags, NULL)); // Associate a package name. StreamingLevel->PackageName = InPackageName; // Seed the level's draw color. StreamingLevel->DrawColor = FColor::MakeRandomColor(); StreamingLevel->LevelTransform = FTransform::Identity; StreamingLevel->PackageNameToLoad = InPackageName; // Add the streaming level to level's world LevelWorld->StreamingLevels.Add(StreamingLevel); LevelWorld->GetOutermost()->MarkPackageDirty(); }
ULevelStreaming* FWorldTileModel::CreateAssosiatedStreamingLevel() { ULevelStreaming* AssociatedStreamingLevel = NULL; ULevel* Level = GetLevelObject(); if (Level) { FName PackageName = Level->GetOutermost()->GetFName(); UWorld* PersistentWorld = LevelCollectionModel.GetWorld(); // Try to find existing object first int32 FoundIndex = PersistentWorld->StreamingLevels.FindMatch(ULevelStreaming::FPackageNameMatcher(PackageName)); if (FoundIndex != INDEX_NONE) { AssociatedStreamingLevel = PersistentWorld->StreamingLevels[FoundIndex]; } else { // Create new streaming level AssociatedStreamingLevel = Cast<ULevelStreaming>( StaticConstructObject(ULevelStreamingKismet::StaticClass(), PersistentWorld, NAME_None, RF_Transient, NULL) ); // AssociatedStreamingLevel->PackageName = PackageName; AssociatedStreamingLevel->DrawColor = FColor::MakeRandomColor(); AssociatedStreamingLevel->LevelTransform = FTransform::Identity; AssociatedStreamingLevel->PackageNameToLoad = PackageName; // PersistentWorld->StreamingLevels.Add(AssociatedStreamingLevel); } } return AssociatedStreamingLevel; }
UObject* UCreateNewObject::K2_NewObjectFromBlueprint(UObject* WorldContextObject, TSubclassOf<UObject> UC) { UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject); UObject* tempObject = StaticConstructObject(UC); return tempObject; }
UVaRestJsonValue* ConstructJsonValue(UObject* WorldContextObject, const TSharedPtr<FJsonValue>& InValue) { TSharedPtr<FJsonValue> NewVal = InValue; UVaRestJsonValue* NewValue = (UVaRestJsonValue*)StaticConstructObject(UVaRestJsonValue::StaticClass()); NewValue->SetRootValue(NewVal); return NewValue; }
UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueObject(UObject* WorldContextObject, UVaRestJsonObject *JsonObject) { TSharedPtr<FJsonValue> NewVal = MakeShareable(new FJsonValueObject(JsonObject->GetRootObject())); UVaRestJsonValue* NewValue = (UVaRestJsonValue*)StaticConstructObject(UVaRestJsonValue::StaticClass()); NewValue->SetRootValue(NewVal); return NewValue; }
UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueBool(UObject* WorldContextObject, bool InValue) { TSharedPtr<FJsonValue> NewVal = MakeShareable(new FJsonValueBoolean(InValue)); UVaRestJsonValue* NewValue = (UVaRestJsonValue*)StaticConstructObject(UVaRestJsonValue::StaticClass()); NewValue->SetRootValue(NewVal); return NewValue; }
UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueNumber(UObject* WorldContextObject, float Number) { TSharedPtr<FJsonValue> NewVal = MakeShareable(new FJsonValueNumber(Number)); UVaRestJsonValue* NewValue = (UVaRestJsonValue*)StaticConstructObject(UVaRestJsonValue::StaticClass()); NewValue->SetRootValue(NewVal); return NewValue; }
UBluEye* UBluBlueprintFunctionLibrary::NewBluEye(UObject* WorldContextObject) { UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject); UBluEye* tempObject = Cast<UBluEye>(StaticConstructObject(UBluEye::StaticClass())); return tempObject; }
UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueString(UObject* WorldContextObject, const FString& StringValue) { TSharedPtr<FJsonValue> NewVal = MakeShareable(new FJsonValueString(StringValue)); UVaRestJsonValue* NewValue = (UVaRestJsonValue*)StaticConstructObject(UVaRestJsonValue::StaticClass()); NewValue->SetRootValue(NewVal); return NewValue; }
UDestructibleMesh* ImportDestructibleMeshFromApexDestructibleAsset(UObject* InParent, NxDestructibleAsset& ApexDestructibleAsset, FName Name, EObjectFlags Flags, FSkeletalMeshImportData* OutData, EImportOptions::Type Options) { // The APEX Destructible Asset contains an APEX Render Mesh Asset, get a pointer to this const physx::NxRenderMeshAsset* ApexRenderMesh = ApexDestructibleAsset.getRenderMeshAsset(); if (ApexRenderMesh == NULL) { return NULL; } // Number of submeshes (aka "elements" in Unreal) const physx::PxU32 SubmeshCount = ApexRenderMesh->getSubmeshCount(); if (SubmeshCount == 0) { return NULL; } // Make sure rendering is done - so we are not changing data being used by collision drawing. FlushRenderingCommands(); UDestructibleMesh* DestructibleMesh = FindObject<UDestructibleMesh>(InParent, *Name.ToString()); if (DestructibleMesh == NULL) { // Create the new UDestructibleMesh object if the one with the same name does not exist DestructibleMesh = CastChecked<UDestructibleMesh>(StaticConstructObject(UDestructibleMesh::StaticClass(), InParent, Name, Flags)); } if (!(Options & EImportOptions::PreserveSettings)) { // Store the current file path and timestamp for re-import purposes // @todo AssetImportData make a data class for Apex destructible assets DestructibleMesh->AssetImportData = ConstructObject<UAssetImportData>(UAssetImportData::StaticClass(), DestructibleMesh); DestructibleMesh->AssetImportData->SourceFilePath = FReimportManager::SanitizeImportFilename(UFactory::CurrentFilename, DestructibleMesh); DestructibleMesh->AssetImportData->SourceFileTimestamp = IFileManager::Get().GetTimeStamp(*UFactory::CurrentFilename).ToString(); } DestructibleMesh->PreEditChange(NULL); // Build FractureSettings from ApexDestructibleAsset in case we want to re-fracture #if WITH_EDITORONLY_DATA DestructibleMesh->CreateFractureSettings(); DestructibleMesh->FractureSettings->BuildRootMeshFromApexDestructibleAsset(ApexDestructibleAsset, Options); // Fill materials DestructibleMesh->FractureSettings->Materials.Reset(DestructibleMesh->Materials.Num()); for (int32 MaterialIndex = 0; MaterialIndex < DestructibleMesh->Materials.Num(); ++MaterialIndex) { DestructibleMesh->FractureSettings->Materials.Insert(DestructibleMesh->Materials[MaterialIndex].MaterialInterface, MaterialIndex); } #endif // WITH_EDITORONLY_DATA if (!SetApexDestructibleAsset(*DestructibleMesh, ApexDestructibleAsset, OutData, Options)) { return NULL; } return DestructibleMesh; }
UObject* FEditorObjectTracker::GetEditorObjectForClass( UClass* EdClass ) { UObject *Obj = (EditorObjMap.Contains(EdClass) ? *EditorObjMap.Find(EdClass) : NULL); if(Obj == NULL) { FString ObjName = MakeUniqueObjectName(GetTransientPackage(), EdClass).ToString(); ObjName += "_EdObj"; Obj = StaticConstructObject(EdClass, GetTransientPackage(), FName(*ObjName), RF_Public|RF_Standalone|RF_Transient); EditorObjMap.Add(EdClass,Obj); } return Obj; }
UVaRestJsonObject* UVaRestJsonValue::AsObject() { if (!JsonVal.IsValid()) { ErrorMessage(TEXT("Object")); return NULL; } TSharedPtr<FJsonObject> NewObj = JsonVal->AsObject(); UVaRestJsonObject* JsonObj = (UVaRestJsonObject*)StaticConstructObject(UVaRestJsonObject::StaticClass()); JsonObj->SetRootObject(NewObj); return JsonObj; }
/** * @return UOject* The object that is mapped by this mapping */ UObject* FBSPSurfaceStaticLighting::GetMappedObject() const { //@todo. THIS WILL SCREW UP IF CALLED MORE THAN ONE TIME!!!! // Create a collection object to allow selection of the surfaces in this mapping ULightmappedSurfaceCollection* MappedObject = CastChecked<ULightmappedSurfaceCollection>( StaticConstructObject(ULightmappedSurfaceCollection::StaticClass())); // Set the owner model MappedObject->SourceModel = Model.Get(); // Fill in the surface index array for (int32 NodeIndex = 0; NodeIndex < NodeGroup->Nodes.Num(); NodeIndex++) { MappedObject->Surfaces.Add(Model->Nodes[NodeGroup->Nodes[NodeIndex]].iSurf); } return MappedObject; }
UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueArray(UObject* WorldContextObject, const TArray<UVaRestJsonValue*>& InArray) { // Prepare data array to create new value TArray< TSharedPtr<FJsonValue> > ValueArray; for (auto InVal : InArray) { ValueArray.Add(InVal->GetRootValue()); } TSharedPtr<FJsonValue> NewVal = MakeShareable(new FJsonValueArray(ValueArray)); UVaRestJsonValue* NewValue = (UVaRestJsonValue*)StaticConstructObject(UVaRestJsonValue::StaticClass()); NewValue->SetRootValue(NewVal); return NewValue; }
void SPropertyEditorEditInline::OnClassPicked(UClass* InClass) { TArray<FObjectBaseAddress> ObjectsToModify; TArray<FString> NewValues; const TSharedRef< FPropertyNode > PropertyNode = PropertyEditor->GetPropertyNode(); FObjectPropertyNode* ObjectNode = PropertyNode->FindObjectItemParent(); if( ObjectNode ) { for ( TPropObjectIterator Itor( ObjectNode->ObjectIterator() ) ; Itor ; ++Itor ) { FString NewValue; if (InClass) { UObject* Object = Itor->Get(); UObject* UseOuter = (InClass->IsChildOf(UClass::StaticClass()) ? Cast<UClass>(Object)->GetDefaultObject() : Object); EObjectFlags MaskedOuterFlags = UseOuter ? UseOuter->GetMaskedFlags(RF_PropagateToSubObjects) : RF_NoFlags; if (UseOuter && UseOuter->HasAnyFlags(RF_ClassDefaultObject | RF_ArchetypeObject)) { MaskedOuterFlags |= RF_ArchetypeObject; } UObject* NewObject = StaticConstructObject(InClass, UseOuter, NAME_None, MaskedOuterFlags, NULL); NewValue = NewObject->GetPathName(); } else { NewValue = FName(NAME_None).ToString(); } NewValues.Add(NewValue); } const TSharedRef< IPropertyHandle > PropertyHandle = PropertyEditor->GetPropertyHandle(); PropertyHandle->SetPerObjectValues( NewValues ); // Force a rebuild of the children when this node changes PropertyNode->RequestRebuildChildren(); ComboButton->SetIsOpen(false); } }
TArray<UVaRestJsonValue*> UVaRestJsonValue::AsArray() const { TArray<UVaRestJsonValue*> OutArray; if (!JsonVal.IsValid()) { ErrorMessage(TEXT("Array")); return OutArray; } TArray< TSharedPtr<FJsonValue> > ValArray = JsonVal->AsArray(); for (auto Value : ValArray) { UVaRestJsonValue* NewValue = (UVaRestJsonValue*)StaticConstructObject(UVaRestJsonValue::StaticClass()); NewValue->SetRootValue(Value); OutArray.Add(NewValue); } return OutArray; }
static UDataTable* CreateGameplayDataTable() { FString CSV(TEXT(",Tag,CategoryText,")); CSV.Append(TEXT("\r\n0,Damage")); CSV.Append(TEXT("\r\n1,Damage.Basic")); CSV.Append(TEXT("\r\n2,Damage.Type1")); CSV.Append(TEXT("\r\n3,Damage.Type2")); CSV.Append(TEXT("\r\n4,Damage.Reduce")); CSV.Append(TEXT("\r\n5,Damage.Buffable")); CSV.Append(TEXT("\r\n6,Damage.Buff")); CSV.Append(TEXT("\r\n7,Damage.Physical")); CSV.Append(TEXT("\r\n8,Damage.Fire")); CSV.Append(TEXT("\r\n9,Damage.Buffed.FireBuff")); CSV.Append(TEXT("\r\n10,Damage.Mitigated.Armor")); CSV.Append(TEXT("\r\n11,Lifesteal")); CSV.Append(TEXT("\r\n12,Shield")); CSV.Append(TEXT("\r\n13,Buff")); CSV.Append(TEXT("\r\n14,Immune")); CSV.Append(TEXT("\r\n15,FireDamage")); CSV.Append(TEXT("\r\n16,ShieldAbsorb")); CSV.Append(TEXT("\r\n17,Stackable")); CSV.Append(TEXT("\r\n18,Stack")); CSV.Append(TEXT("\r\n19,Stack.CappedNumber")); CSV.Append(TEXT("\r\n20,Stack.DiminishingReturns")); CSV.Append(TEXT("\r\n21,Protect.Damage")); CSV.Append(TEXT("\r\n22,SpellDmg.Buff")); CSV.Append(TEXT("\r\n23,GameplayCue.Burning")); UDataTable * DataTable = Cast<UDataTable>(StaticConstructObject(UDataTable::StaticClass(), GetTransientPackage(), FName(TEXT("TempDataTable")))); DataTable->RowStruct = FGameplayTagTableRow::StaticStruct(); DataTable->CreateTableFromCSVString(CSV); FGameplayTagTableRow * Row = (FGameplayTagTableRow*)DataTable->RowMap["0"]; if (Row) { check(Row->Tag == TEXT("Damage")); } return DataTable; }
void UGameplayEffectExtension_LifestealTest::PostGameplayEffectExecute(const FGameplayModifierEvaluatedData &SelfData, const FGameplayEffectModCallbackData &Data) const { IGameplayTagsModule& GameplayTagsModule = IGameplayTagsModule::Get(); float DamageDone = Data.EvaluatedData.Magnitude; float LifestealPCT = SelfData.Magnitude; float HealthToRestore = -DamageDone * LifestealPCT; if (HealthToRestore > 0.f) { UAbilitySystemComponent *Source = Data.EffectSpec.GetContext().GetOriginalInstigatorAbilitySystemComponent(); UGameplayEffect * LocalHealthRestore = HealthRestoreGameplayEffect; if (!LocalHealthRestore) { UProperty *HealthProperty = FindFieldChecked<UProperty>(UAbilitySystemTestAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED(UAbilitySystemTestAttributeSet, Health)); // Since this is a test class and we don't want to tie it any actual content assets, just construct a GameplayEffect here. LocalHealthRestore = Cast<UGameplayEffect>(StaticConstructObject(UGameplayEffect::StaticClass(), GetTransientPackage(), FName(TEXT("LifestealHealthRestore")))); LocalHealthRestore->Modifiers.SetNum(1); LocalHealthRestore->Modifiers[0].Magnitude.SetValue(HealthToRestore); LocalHealthRestore->Modifiers[0].ModifierOp = EGameplayModOp::Additive; LocalHealthRestore->Modifiers[0].Attribute.SetUProperty(HealthProperty); LocalHealthRestore->DurationPolicy = EGameplayEffectDurationType::Instant; LocalHealthRestore->Period.Value = UGameplayEffect::NO_PERIOD; } if (SelfData.Handle.IsValid()) { // We are coming from an active gameplay effect check(SelfData.Handle.IsValid()); } // Apply a GameplayEffect to restore health // We make the GameplayEffect's level = the health restored. This is one approach. We could also // try a basic restore 1 health item but apply a 2nd GE to modify that - but that seems like too many levels of indirection Source->ApplyGameplayEffectToSelf(LocalHealthRestore, HealthToRestore, Source->GetEffectContext()); } }
UTexture2DDynamic* UTexture2DDynamic::Create(int32 InSizeX, int32 InSizeY, EPixelFormat InFormat, bool InIsResolveTarget) { EPixelFormat DesiredFormat = EPixelFormat(InFormat); if (InSizeX > 0 && InSizeY > 0 ) { UTexture2DDynamic* NewTexture = Cast<UTexture2DDynamic>(StaticConstructObject(GetClass(), GetTransientPackage(), NAME_None, RF_Transient)); if (NewTexture != NULL) { // Disable compression NewTexture->CompressionSettings = TC_Default; #if WITH_EDITORONLY_DATA NewTexture->CompressionNone = true; NewTexture->MipGenSettings = TMGS_NoMipmaps; NewTexture->CompressionNoAlpha = true; NewTexture->DeferCompression = false; #endif // #if WITH_EDITORONLY_DATA if ( InIsResolveTarget ) { // NewTexture->SRGB = false; NewTexture->bNoTiling = false; } else { // Untiled format NewTexture->bNoTiling = true; } NewTexture->Init(InSizeX, InSizeY, DesiredFormat, InIsResolveTarget); } return NewTexture; } else { UE_LOG(LogTexture, Warning, TEXT("Invalid parameters specified for UTexture2DDynamic::Create()")); return NULL; } }
FCameraShakeInstance UCameraModifier_CameraShake::InitializeShake(TSubclassOf<class UCameraShake> NewShake, float Scale, ECameraAnimPlaySpace PlaySpace, FRotator UserPlaySpaceRot) { FCameraShakeInstance Inst; Inst.SourceShakeName = NewShake->GetFName(); // Create a camera shake object of class NewShake Inst.SourceShake = Cast<UCameraShake>(StaticConstructObject(NewShake, this)); Inst.Scale = Scale; if (GEngine->IsSplitScreen(CameraOwner->GetWorld())) { Scale *= SplitScreenShakeScale; } // init oscillations if ( Inst.SourceShake->OscillationDuration != 0.f ) { Inst.RotSinOffset.X = InitializeOffset( Inst.SourceShake->RotOscillation.Pitch ); Inst.RotSinOffset.Y = InitializeOffset( Inst.SourceShake->RotOscillation.Yaw ); Inst.RotSinOffset.Z = InitializeOffset( Inst.SourceShake->RotOscillation.Roll ); Inst.LocSinOffset.X = InitializeOffset( Inst.SourceShake->LocOscillation.X ); Inst.LocSinOffset.Y = InitializeOffset( Inst.SourceShake->LocOscillation.Y ); Inst.LocSinOffset.Z = InitializeOffset( Inst.SourceShake->LocOscillation.Z ); Inst.FOVSinOffset = InitializeOffset( Inst.SourceShake->FOVOscillation ); Inst.OscillatorTimeRemaining = Inst.SourceShake->OscillationDuration; if (Inst.SourceShake->OscillationBlendInTime > 0.f) { Inst.bBlendingIn = true; Inst.CurrentBlendInTime = 0.f; } } // init anims if (Inst.SourceShake->Anim != NULL) { bool bLoop = false; bool bRandomStart = false; float Duration = 0.f; if (Inst.SourceShake->bRandomAnimSegment) { bLoop = true; bRandomStart = true; Duration = Inst.SourceShake->RandomAnimSegmentDuration; } if (Scale > 0.f) { Inst.AnimInst = CameraOwner->PlayCameraAnim(Inst.SourceShake->Anim, Inst.SourceShake->AnimPlayRate, Scale, Inst.SourceShake->AnimBlendInTime, Inst.SourceShake->AnimBlendOutTime, bLoop, bRandomStart, Duration, Inst.SourceShake->bSingleInstance); if (PlaySpace != CAPS_CameraLocal && Inst.AnimInst != NULL) { Inst.AnimInst->SetPlaySpace(PlaySpace, UserPlaySpaceRot); } } } Inst.PlaySpace = PlaySpace; if (Inst.PlaySpace == CAPS_UserDefined) { Inst.UserPlaySpaceMatrix = FRotationMatrix(UserPlaySpaceRot); } return Inst; }
UObject* UMovieSceneFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn) { return StaticConstructObject( UMovieScene::StaticClass(), InParent, Name, Flags ); }
ULocalPlayer* UGameInstance::CreateLocalPlayer(int32 ControllerId, FString& OutError, bool bSpawnActor) { checkf(GetEngine()->LocalPlayerClass != NULL); ULocalPlayer* NewPlayer = NULL; int32 InsertIndex = INDEX_NONE; const int32 MaxSplitscreenPlayers = (GetGameViewportClient() != NULL) ? GetGameViewportClient()->MaxSplitscreenPlayers : 1; if (FindLocalPlayerFromControllerId( ControllerId ) != NULL) { OutError = FString::Printf(TEXT("A local player already exists for controller ID %d,"), ControllerId); } else if (LocalPlayers.Num() < MaxSplitscreenPlayers) { // If the controller ID is not specified then find the first available if (ControllerId < 0) { for (ControllerId = 0; ControllerId < MaxSplitscreenPlayers; ++ControllerId) { if (FindLocalPlayerFromControllerId( ControllerId ) == NULL) { break; } } check(ControllerId < MaxSplitscreenPlayers); } else if (ControllerId >= MaxSplitscreenPlayers) { UE_LOG(LogPlayerManagement, Warning, TEXT("Controller ID (%d) is unlikely to map to any physical device, so this player will not receive input"), ControllerId); } NewPlayer = CastChecked<ULocalPlayer>(StaticConstructObject(GetEngine()->LocalPlayerClass, GetEngine())); InsertIndex = AddLocalPlayer(NewPlayer, ControllerId); if (bSpawnActor && InsertIndex != INDEX_NONE && GetWorld() != NULL) { if (GetWorld()->GetNetMode() != NM_Client) { // server; spawn a new PlayerController immediately if (!NewPlayer->SpawnPlayActor("", OutError, GetWorld())) { RemoveLocalPlayer(NewPlayer); NewPlayer = NULL; } } else { // client; ask the server to let the new player join NewPlayer->SendSplitJoin(); } } } else { OutError = FString::Printf(TEXT( "Maximum number of players (%d) already created. Unable to create more."), MaxSplitscreenPlayers); } if (OutError != TEXT("")) { UE_LOG(LogPlayerManagement, Log, TEXT("UPlayer* creation failed with error: %s"), *OutError); } return NewPlayer; }
bool UDemoNetDriver::InitConnect( FNetworkNotify* InNotify, const FURL& ConnectURL, FString& Error ) { // handle default initialization if ( !InitBase( true, InNotify, ConnectURL, false, Error ) ) { return false; } // open the pre-recorded demo file FileAr = IFileManager::Get().CreateFileReader( *DemoFilename ); if ( !FileAr ) { Error = FString::Printf( TEXT( "Couldn't open demo file %s for reading" ), *DemoFilename ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); return false; } // Playback, local machine is a client, and the demo stream acts "as if" it's the server. ServerConnection = ConstructObject<UNetConnection>( UDemoNetConnection::StaticClass() ); ServerConnection->InitConnection( this, USOCK_Pending, ConnectURL, 1000000 ); #if 1 // Create fake control channel ServerConnection->CreateChannel( CHTYPE_Control, 1 ); #endif // use the same byte format regardless of platform so that the demos are cross platform // DEMO_FIXME: This is messing up for some reason, investigate //FileAr->SetByteSwapping( true ); int32 EngineVersion = 0; (*FileAr) << EngineVersion; (*FileAr) << PlaybackTotalFrames; UE_LOG( LogDemo, Log, TEXT( "Starting demo playback with demo. Filename: %s, Frames: %i, Version %i" ), *DemoFilename, PlaybackTotalFrames, EngineVersion ); #if 1 // Bypass UDemoPendingNetLevel FString LevelName; (*FileAr) << LevelName; FString LoadMapError; FURL DemoURL; DemoURL.Map = LevelName; FWorldContext * WorldContext = GEngine->GetWorldContextFromWorld( World ); if ( WorldContext == NULL ) { Error = FString::Printf( TEXT( "No world context" ), *DemoFilename ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); return false; } World->DemoNetDriver = NULL; SetWorld( NULL ); UDemoPendingNetGame * NewPendingNetGame = new UDemoPendingNetGame( FPostConstructInitializeProperties() ); NewPendingNetGame->DemoNetDriver = this; WorldContext->PendingNetGame = NewPendingNetGame; if ( !GEngine->LoadMap( *WorldContext, DemoURL, NewPendingNetGame, LoadMapError ) ) { Error = LoadMapError; UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: LoadMap failed: failed: %s" ), *Error ); return false; } SetWorld( WorldContext->World() ); WorldContext->World()->DemoNetDriver = this; WorldContext->PendingNetGame = NULL; #endif int32 NumStreamingLevels = 0; (*FileAr) << NumStreamingLevels; for ( int32 i = 0; i < NumStreamingLevels; ++i ) { ULevelStreamingKismet* StreamingLevel = static_cast<ULevelStreamingKismet*>(StaticConstructObject(ULevelStreamingKismet::StaticClass(), GetWorld(), NAME_None, RF_NoFlags, NULL ) ); StreamingLevel->bShouldBeLoaded = true; StreamingLevel->bShouldBeVisible = true; StreamingLevel->bShouldBlockOnLoad = false; StreamingLevel->bInitiallyLoaded = true; StreamingLevel->bInitiallyVisible = true; FString PackageName; FString PackageNameToLoad; (*FileAr) << PackageName; (*FileAr) << PackageNameToLoad; (*FileAr) << StreamingLevel->LevelTransform; StreamingLevel->PackageNameToLoad = FName( *PackageNameToLoad ); StreamingLevel->SetWorldAssetByPackageName( FName( *PackageName ) ); GetWorld()->StreamingLevels.Add( StreamingLevel ); UE_LOG( LogDemo, Log, TEXT( " Loading streamingLevel: %s, %s" ), *PackageName, *PackageNameToLoad ); } DemoDeltaTime = 0; return true; }
bool FTextPropertyTest::RunTest (const FString& Parameters) { UClass* const TextPropertyTestObjectClass = UTextPropertyTestObject::StaticClass(); UTextProperty* const DefaultedTextProperty = FindField<UTextProperty>(TextPropertyTestObjectClass, "DefaultedText"); UTextProperty* const UndefaultedTextProperty = FindField<UTextProperty>(TextPropertyTestObjectClass, "UndefaultedText"); UTextPropertyTestObject* const TextPropertyTestCDO = Cast<UTextPropertyTestObject>( TextPropertyTestObjectClass->ClassDefaultObject ); { UTextPropertyTestObject* NewObject = Cast<UTextPropertyTestObject>( StaticConstructObject( TextPropertyTestObjectClass ) ); // Test Identical - Newly constructed object properties should be identical to class default object properties. if( (DefaultedTextProperty->Identical(&(NewObject->DefaultedText), &(TextPropertyTestCDO->DefaultedText), 0) != true) || (UndefaultedTextProperty->Identical(&(NewObject->UndefaultedText), &(TextPropertyTestCDO->UndefaultedText), 0) != true) ) { AddError(TEXT("UTextProperty::Identical failed to return true comparing a newly constructed object and the class default object.")); } // Test ExportText - Export text should provide the localized form of the text. { FString ExportedStringValue; DefaultedTextProperty->ExportTextItem(ExportedStringValue, &(NewObject->DefaultedText), NULL, NULL, 0, NULL); if( ExportedStringValue != NewObject->DefaultedText.ToString() ) { AddError(TEXT("UTextProperty::ExportTextItem failed to provide the display string.")); } } // Test ImportText - Import text should set the source string to the input string. { FString ImportedStringValue = TEXT("ImportValue"); DefaultedTextProperty->ImportText(*ImportedStringValue, &(NewObject->DefaultedText), 0, NULL); const FString* const SourceString = FTextInspector::GetSourceString(NewObject->DefaultedText); if( !SourceString || ImportedStringValue != *SourceString ) { AddError(TEXT("UTextProperty::ImportText failed to alter the source string to the provided value.")); } } } // Test Identical - Altered text properties should not be identical to class default object properties. { UTextPropertyTestObject* NewObject = Cast<UTextPropertyTestObject>( StaticConstructObject( TextPropertyTestObjectClass ) ); NewObject->DefaultedText = LOCTEXT("ModifiedDefaultedText", "Modified DefaultedText Value"); NewObject->UndefaultedText = LOCTEXT("ModifiedUndefaultedText", "Modified UndefaultedText Value"); if( DefaultedTextProperty->Identical(&(NewObject->DefaultedText), &(TextPropertyTestCDO->DefaultedText), 0) || UndefaultedTextProperty->Identical(&(NewObject->UndefaultedText), &(TextPropertyTestCDO->UndefaultedText), 0) ) { AddError(TEXT("UTextProperty::Identical failed to return false comparing a modified object and the class default object.")); } } { TArray<uint8> BackingStore; UTextPropertyTestObject* SavedObject = Cast<UTextPropertyTestObject>(StaticConstructObject(UTextPropertyTestObject::StaticClass())); FText::FindText( TEXT("TextPropertyTest"), TEXT("DefaultedText"), /*OUT*/SavedObject->DefaultedText ); SavedObject->UndefaultedText = LOCTEXT("ModifiedUndefaultedText", "Modified UndefaultedText Value"); const FText TransientText = FText::Format( LOCTEXT("TransientTest", "{0}"), LOCTEXT("TransientTestMessage", "Testing Transient serialization detection") ); SavedObject->TransientText = TransientText; // Test Identical - Text properties with the same source as class default object properties should be considered identical. if( !( DefaultedTextProperty->Identical(&(SavedObject->DefaultedText), &(TextPropertyTestCDO->DefaultedText), 0) ) ) { AddError(TEXT("UTextProperty::Identical failed to return true comparing an FText with an identical source string to the class default object.")); } // Save. { FMemoryWriter MemoryWriter(BackingStore, true); SavedObject->Serialize(MemoryWriter); } UTextPropertyTestObject* LoadedObject = Cast<UTextPropertyTestObject>(StaticConstructObject(UTextPropertyTestObject::StaticClass())); // Load. { FMemoryReader MemoryReader(BackingStore, true); LoadedObject->Serialize(MemoryReader); } // Test Serialization - Loaded object should be identical to saved object. if( !( DefaultedTextProperty->Identical(&(LoadedObject->DefaultedText), &(SavedObject->DefaultedText), 0) ) || !( UndefaultedTextProperty->Identical(&(LoadedObject->UndefaultedText), &(SavedObject->UndefaultedText), 0) ) ) { AddError(TEXT("Saving and loading a serialized object containing FText properties failed to maintain FText values.")); } // Test Identical - Text properties with the same source as the class default object property should save and load as the class default object property. if( !( DefaultedTextProperty->Identical(&(LoadedObject->DefaultedText), &(TextPropertyTestCDO->DefaultedText), 0) ) ) { AddError(TEXT("UTextProperty::Identical failed to collapse identical source strings into the same namespace and key during serialization.")); } // Test Transient - Transient text properties should save out an error message instead of their actual string value const FString* const LoadedTransientTextString = FTextInspector::GetSourceString(LoadedObject->TransientText); const FString* const TransientTextString = FTextInspector::GetSourceString(TransientText); if ( GIsEditor && LoadedTransientTextString && TransientTextString && *(LoadedTransientTextString) != *(TransientTextString) ) { AddError(TEXT("Transient Texts should not exist in the editor.")); } else if ( !GIsEditor && LoadedObject->TransientText.ToString() != FText::Format( FText::SerializationFailureError, TransientText ).ToString() ) { //AddError(TEXT("Transient Texts should persist an error message when they are serialized.")); } } return true; }
// Some Comment void FHTTPAdminPlugin::StartupModule() { UHTTPAdmin* HTTPAdmin = Cast<UHTTPAdmin>(StaticConstructObject(UHTTPAdmin::StaticClass())); HTTPAdmin->Init(); }
bool UDemoNetDriver::InitConnect( FNetworkNotify* InNotify, const FURL& ConnectURL, FString& Error ) { if ( GetWorld() == nullptr ) { UE_LOG( LogDemo, Error, TEXT( "GetWorld() == nullptr" ) ); return false; } if ( GetWorld()->GetGameInstance() == nullptr ) { UE_LOG( LogDemo, Error, TEXT( "GetWorld()->GetGameInstance() == nullptr" ) ); return false; } UGameInstance* GameInstance = GetWorld()->GetGameInstance(); // handle default initialization if ( !InitBase( true, InNotify, ConnectURL, false, Error ) ) { GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::Generic, FString( TEXT( "InitBase FAILED" ) ) ); return false; } ResetDemoState(); // open the pre-recorded demo file FileAr = IFileManager::Get().CreateFileReader( *DemoFilename ); if ( !FileAr ) { Error = FString::Printf( TEXT( "Couldn't open demo file %s for reading" ), *DemoFilename ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::DemoNotFound, FString( EDemoPlayFailure::ToString( EDemoPlayFailure::DemoNotFound ) ) ); return false; } // Playback, local machine is a client, and the demo stream acts "as if" it's the server. ServerConnection = ConstructObject<UNetConnection>( UDemoNetConnection::StaticClass() ); ServerConnection->InitConnection( this, USOCK_Pending, ConnectURL, 1000000 ); // use the same byte format regardless of platform so that the demos are cross platform // DEMO_FIXME: This is messing up for some reason, investigate //FileAr->SetByteSwapping( true ); FNetworkDemoHeader DemoHeader; (*FileAr) << DemoHeader; // Check magic value if ( DemoHeader.Magic != NETWORK_DEMO_MAGIC ) { Error = FString( TEXT( "Demo file is corrupt" ) ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::Corrupt, Error ); return false; } // Check version if ( DemoHeader.Version != NETWORK_DEMO_VERSION ) { Error = FString( TEXT( "Demo file version is incorrect" ) ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::InvalidVersion, Error ); return false; } // Create fake control channel ServerConnection->CreateChannel( CHTYPE_Control, 1 ); DemoTotalFrames = DemoHeader.NumFrames; DemoTotalTime = DemoHeader.TotalTime; UE_LOG( LogDemo, Log, TEXT( "Starting demo playback with demo. Filename: %s, Frames: %i, Version %i" ), *DemoFilename, DemoTotalFrames, DemoHeader.Version ); // Bypass UDemoPendingNetLevel FString LoadMapError; FURL DemoURL; DemoURL.Map = DemoHeader.LevelName; FWorldContext * WorldContext = GEngine->GetWorldContextFromWorld( GetWorld() ); if ( WorldContext == NULL ) { Error = FString::Printf( TEXT( "No world context" ), *DemoFilename ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::Generic, FString( TEXT( "No world context" ) ) ); return false; } GetWorld()->DemoNetDriver = NULL; SetWorld( NULL ); auto NewPendingNetGame = NewObject<UDemoPendingNetGame>(); NewPendingNetGame->DemoNetDriver = this; WorldContext->PendingNetGame = NewPendingNetGame; if ( !GEngine->LoadMap( *WorldContext, DemoURL, NewPendingNetGame, LoadMapError ) ) { Error = LoadMapError; UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: LoadMap failed: failed: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::Generic, FString( TEXT( "LoadMap failed" ) ) ); return false; } SetWorld( WorldContext->World() ); WorldContext->World()->DemoNetDriver = this; WorldContext->PendingNetGame = NULL; // Remember where we are const int32 OldPos = FileAr->Tell(); // Jump to meta data FileAr->Seek( DemoHeader.MetaDataOffset ); // Read meta data for ( int32 i = 0; i < DemoHeader.NumStreamingLevels; ++i ) { ULevelStreamingKismet* StreamingLevel = static_cast<ULevelStreamingKismet*>(StaticConstructObject(ULevelStreamingKismet::StaticClass(), GetWorld(), NAME_None, RF_NoFlags, NULL ) ); StreamingLevel->bShouldBeLoaded = true; StreamingLevel->bShouldBeVisible = true; StreamingLevel->bShouldBlockOnLoad = false; StreamingLevel->bInitiallyLoaded = true; StreamingLevel->bInitiallyVisible = true; FString PackageName; FString PackageNameToLoad; (*FileAr) << PackageName; (*FileAr) << PackageNameToLoad; (*FileAr) << StreamingLevel->LevelTransform; StreamingLevel->PackageNameToLoad = FName( *PackageNameToLoad ); StreamingLevel->SetWorldAssetByPackageName( FName( *PackageName ) ); GetWorld()->StreamingLevels.Add( StreamingLevel ); UE_LOG( LogDemo, Log, TEXT( " Loading streamingLevel: %s, %s" ), *PackageName, *PackageNameToLoad ); } // Jump back to start of stream FileAr->Seek( OldPos ); // Remember where the meta data is, this is where we must stop reading the demo stream EndOfStreamOffset = DemoHeader.MetaDataOffset; return true; }
FWorldTileModel::FWorldTileModel(const TWeakObjectPtr<UEditorEngine>& InEditor, FWorldTileCollectionModel& InWorldModel, int32 InTileIdx) : FLevelModel(InWorldModel, InEditor) , TileIdx(InTileIdx) , TileDetails(NULL) , bWasShelved(false) { UWorldComposition* WorldComposition = LevelCollectionModel.GetWorld()->WorldComposition; // Tile display details object TileDetails = Cast<UWorldTileDetails>( StaticConstructObject(UWorldTileDetails::StaticClass(), GetTransientPackage(), NAME_None, RF_RootSet|RF_Transient, NULL ) ); // Subscribe to tile properties changes TileDetails->PositionChangedEvent.AddRaw(this, &FWorldTileModel::OnPositionPropertyChanged); TileDetails->ParentPackageNameChangedEvent.AddRaw(this, &FWorldTileModel::OnParentPackageNamePropertyChanged); TileDetails->AlwaysLoadedChangedEvent.AddRaw(this, &FWorldTileModel::OnAlwaysLoadedPropertyChanged); TileDetails->StreamingLevelsChangedEvent.AddRaw(this, &FWorldTileModel::OnStreamingLevelsPropertyChanged); TileDetails->LODSettingsChangedEvent.AddRaw(this, &FWorldTileModel::OnLODSettingsPropertyChanged); TileDetails->ZOrderChangedEvent.AddRaw(this, &FWorldTileModel::OnZOrderPropertyChanged); // Initialize tile details if (WorldComposition->GetTilesList().IsValidIndex(TileIdx)) { FWorldCompositionTile& Tile = WorldComposition->GetTilesList()[TileIdx]; TileDetails->SetInfo(Tile.Info); TileDetails->SyncStreamingLevels(*this); TileDetails->PackageName = Tile.PackageName; TileDetails->bPersistentLevel = false; // Asset name for storing tile thumbnail inside package //FString AssetNameString = FString::Printf(TEXT("%s %s.TheWorld:PersistentLevel"), *ULevel::StaticClass()->GetName(), *Tile.PackageName.ToString()); FString AssetNameString = FString::Printf(TEXT("%s %s"), *UPackage::StaticClass()->GetName(), *Tile.PackageName.ToString()); AssetName = FName(*AssetNameString); // Assign level object in case this level already loaded UPackage* LevelPackage = Cast<UPackage>(StaticFindObjectFast( UPackage::StaticClass(), NULL, Tile.PackageName) ); if (LevelPackage) { // Find the world object UWorld* World = UWorld::FindWorldInPackage(LevelPackage); if (World) { LoadedLevel = World->PersistentLevel; // Enable tile properties TileDetails->bTileEditable = true; } } } else { TileDetails->PackageName = LevelCollectionModel.GetWorld()->GetOutermost()->GetFName(); TileDetails->bPersistentLevel = true; LoadedLevel = LevelCollectionModel.GetWorld()->PersistentLevel; } }