void UChildActorComponent::OnRegister() { Super::OnRegister(); if (ChildActor) { if (ChildActor->GetClass() != ChildActorClass) { DestroyChildActor(); CreateChildActor(); } else { ChildActorName = ChildActor->GetFName(); USceneComponent* ChildRoot = ChildActor->GetRootComponent(); if (ChildRoot && ChildRoot->GetAttachParent() != this) { // attach new actor to this component // we can't attach in CreateChildActor since it has intermediate Mobility set up // causing spam with inconsistent mobility set up // so moving Attach to happen in Register ChildRoot->AttachToComponent(this, FAttachmentTransformRules::SnapToTargetNotIncludingScale); } // Ensure the components replication is correctly initialized SetIsReplicated(ChildActor->GetIsReplicated()); } } else if (ChildActorClass) { CreateChildActor(); } }
UAimPredictionSC::UAimPredictionSC() { // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features // off to improve performance if you don't need them. PrimaryComponentTick.bCanEverTick = true; // ... SetIsReplicated(true); nextRotation = RelativeRotation; }
USCarryObjectComponent::USCarryObjectComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { MaxPickupDistance = 600; RotateSpeed = 10.0f; bUsePawnControlRotation = true; bDoCollisionTest = false; SetIsReplicated(true); }
void UGameplayDebuggingComponent::Deactivate() { #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) Super::Deactivate(); SetComponentTickEnabled(false); SetIsReplicated(false); #else Super::Deactivate(); #endif }
void UGameplayDebuggingComponent::Activate(bool bReset) { #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) Super::Activate(bReset); SetComponentTickEnabled(true); SetIsReplicated(true); #else Super::Activate(bReset); #endif }
UARActionStateComponent::UARActionStateComponent(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { SetIsReplicated(true); bReplicates = true; bWantsInitializeComponent = true; PlayRechargeAnimation = false; IsCasting = false; IsRecharing = false; ActiveState = PCIP.CreateDefaultSubobject<UARActionStateActive>(this, TEXT("StateActive")); CooldownState = PCIP.CreateDefaultSubobject<UARActionStateCooldown>(this, TEXT("StateCooldown")); }
UValorStatComponent::UValorStatComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { bWantsBeginPlay = true; PrimaryComponentTick.bCanEverTick = false; PrimaryComponentTick.bStartWithTickEnabled = false; bAutoActivate = true; SetNetAddressable(); SetIsReplicated(true); BonusHealth = 0.f; BonusHealthRegen = 0.f; }
UARBeamCue::UARBeamCue(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { SetIsReplicated(true); PrimaryComponentTick.bCanEverTick = true; PrimaryComponentTick.bStartWithTickEnabled = true; PrimaryComponentTick.bRunOnAnyThread = true; PrimaryComponentTick.TickGroup = ETickingGroup::TG_DuringPhysics; bTickInEditor = true; bAllowConcurrentTick = true; bAutoRegister = true; bWantsInitializeComponent = true; IsFiring = false; UpdateInterval = 0.1f; }
UARFXEffectComponent::UARFXEffectComponent(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { SetIsReplicated(true); }
UPhysicsMovementComponent::UPhysicsMovementComponent() : movementForce(100000) { PrimaryComponentTick.bCanEverTick = true; SetNetAddressable(); SetIsReplicated(true); }
void UChildActorComponent::CreateChildActor() { AActor* MyOwner = GetOwner(); if (MyOwner && !MyOwner->HasAuthority()) { AActor* ChildClassCDO = (ChildActorClass ? ChildActorClass->GetDefaultObject<AActor>() : nullptr); if (ChildClassCDO && ChildClassCDO->GetIsReplicated()) { // If we belong to an actor that is not authoritative and the child class is replicated then we expect that Actor will be replicated across so don't spawn one return; } } // Kill spawned actor if we have one DestroyChildActor(); // If we have a class to spawn. if(ChildActorClass != nullptr) { UWorld* World = GetWorld(); if(World != nullptr) { // Before we spawn let's try and prevent cyclic disaster bool bSpawn = true; AActor* Actor = MyOwner; while (Actor && bSpawn) { if (Actor->GetClass() == ChildActorClass) { bSpawn = false; UE_LOG(LogChildActorComponent, Error, TEXT("Found cycle in child actor component '%s'. Not spawning Actor of class '%s' to break."), *GetPathName(), *ChildActorClass->GetName()); } Actor = Actor->GetParentActor(); } if (bSpawn) { FActorSpawnParameters Params; Params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; Params.bDeferConstruction = true; // We defer construction so that we set ParentComponent prior to component registration so they appear selected Params.bAllowDuringConstructionScript = true; Params.OverrideLevel = (MyOwner ? MyOwner->GetLevel() : nullptr); Params.Name = ChildActorName; Params.Template = ChildActorTemplate; if (!HasAllFlags(RF_Transactional)) { Params.ObjectFlags &= ~RF_Transactional; } // Spawn actor of desired class ConditionalUpdateComponentToWorld(); FVector Location = GetComponentLocation(); FRotator Rotation = GetComponentRotation(); ChildActor = World->SpawnActor(ChildActorClass, &Location, &Rotation, Params); // If spawn was successful, if(ChildActor != nullptr) { ChildActorName = ChildActor->GetFName(); // Remember which component spawned it (for selection in editor etc) FActorParentComponentSetter::Set(ChildActor, this); // Parts that we deferred from SpawnActor const FComponentInstanceDataCache* ComponentInstanceData = (CachedInstanceData ? CachedInstanceData->ComponentInstanceData : nullptr); ChildActor->FinishSpawning(ComponentToWorld, false, ComponentInstanceData); ChildActor->AttachToComponent(this, FAttachmentTransformRules::SnapToTargetNotIncludingScale); SetIsReplicated(ChildActor->GetIsReplicated()); } } } } // This is no longer needed if (CachedInstanceData) { delete CachedInstanceData; CachedInstanceData = nullptr; } }