void AProjectile::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { LaunchBlast->Deactivate(); // My solution of Radial Forces and caching //auto ForceLocation = CollisionMesh->GetComponentLocation(); //ExplosionForce->SetWorldLocation(ForceLocation); ExplosionForce->FireImpulse(); SetRootComponent(ImpactBlast); ImpactBlast->Activate(); CollisionMesh->DestroyComponent(); UGameplayStatics::ApplyRadialDamage( this, ProjectileDamage, GetActorLocation(), ExplosionForce->Radius, UDamageType::StaticClass(), TArray<AActor*>() //damage all actors ); FTimerHandle TimeHandler; GetWorld()->GetTimerManager().SetTimer(TimeHandler,this, &AProjectile::TimerExpired, DestroyDelay, false); }
void AProjectile::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { // Disable Smoke Trail FX LaunchBlast->Deactivate(); // Activate Explosion FX ImpactBlast->Activate(); // Add Impule to all Actors ExplosionForce->FireImpulse(); // Destroy Collision Mesh and promote children SetRootComponent(ImpactBlast); CollisionMesh->DestroyComponent(); UGameplayStatics::ApplyRadialDamage( this, ProjectileDamage, GetActorLocation(), ExplosionForce->Radius, UDamageType::StaticClass(), TArray<AActor*>() // damage all actors ); FTimerHandle Timer; // OUT Paramter GetWorld()->GetTimerManager().SetTimer(Timer, this, &AProjectile::OnTimerExpire, DestroyDelay, false); }
// Sets default values AShip::AShip(const FObjectInitializer &ObjectInitializer) { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; mesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("StaticMesh")); collision = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("BoxCollider")); shootSound = ObjectInitializer.CreateDefaultSubobject<UAudioComponent>(this, TEXT("ShootSound")); deathSound = ObjectInitializer.CreateDefaultSubobject<UAudioComponent>(this, TEXT("DeathSound")); SetRootComponent(mesh); shootSound->AttachTo(mesh); deathSound->AttachTo(mesh); collision->AttachTo(mesh); shootSound->bAutoActivate = false; deathSound->bAutoActivate = false; collision->bGenerateOverlapEvents = true; collision->SetRelativeLocation(FVector(0, 0, 30)); collision->SetBoxExtent(FVector(48, 48, 32)); speed = 100; OnActorBeginOverlap.AddDynamic(this, &AShip::OnBeginOverlap); }
// Sets default values AProjectile::AProjectile() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = false; CollisionMesh = CreateDefaultSubobject<UStaticMeshComponent>(FName("Collision Mesh")); SetRootComponent(CollisionMesh); // (Simulation Generates Hit Events in BP) CollisionMesh->SetNotifyRigidBodyCollision(true); // if a class is made inheriting from this one, this checkbox will be ticked by default CollisionMesh->SetVisibility(false); LaunchBlast = CreateDefaultSubobject<UParticleSystemComponent>(FName("Launch Blast")); // Attach it to the root component so that the mesh deposits smoke behind it LaunchBlast->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); // TODO Update to new API ProjectileMovingComponent = CreateDefaultSubobject<UProjectileMovementComponent>(FName("Moving Component")); ProjectileMovingComponent->bAutoActivate = false; ImpactBlast = CreateDefaultSubobject<UParticleSystemComponent>(FName("Impact Blast")); ImpactBlast->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); ImpactBlast->bAutoActivate = false; ExplosionForce = CreateDefaultSubobject<URadialForceComponent>(FName("Explosion Force")); ExplosionForce->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); }
// Sets default values AHealthPickup::AHealthPickup() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; //Initialization of components BoxComp = CreateDefaultSubobject<UBoxComponent>(FName("BoxComp")); SetRootComponent(BoxComp); HealthKitSM = CreateDefaultSubobject<UStaticMeshComponent>(FName("HealthKitSM")); ParticleSystemComp = CreateDefaultSubobject<UParticleSystemComponent>(FName("ParticleSystemComp")); ParticleSystemComp->AttachTo(GetRootComponent()); HealthKitSM->AttachTo(ParticleSystemComp); RotatingMovementComp = CreateDefaultSubobject<URotatingMovementComponent>(FName("RotatingMovementComp")); //Just an initial value HealthToProvide = 10.f; }
// Sets default values ASmokePawn::ASmokePawn() { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; AIControllerClass = ASmokeAIController::StaticClass(); collision = CreateDefaultSubobject<USphereComponent>(TEXT("SmokeCollision")); SetRootComponent(collision); collision->SetSimulatePhysics(true); collision->SetEnableGravity(false); collision->SetCollisionProfileName(FName("Pawn")); collision->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap); smokeParticleSystem = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("SmokeParticle")); smokeParticleSystem->AttachTo(GetRootComponent()); ConstructorHelpers::FObjectFinder<UParticleSystem> particleAsset(TEXT("/Game/Particles/P_Smoke_AI")); smokeParticleSystem->SetTemplate(particleAsset.Object); movement = CreateDefaultSubobject<UFloatingPawnMovement>(TEXT("SmokeMovement")); movement->SetUpdatedComponent(GetRootComponent()); movement->MaxSpeed = 100.0f; movement->Acceleration = 100.0f; movement->Deceleration = 0.0; ConstructorHelpers::FObjectFinder<UBehaviorTree> behaviorAsset(TEXT("/Game/AI/SmokeBrain")); behavior = behaviorAsset.Object; }
// Sets default values ALaser::ALaser() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; root = CreateDefaultSubobject<UEmptyComponent>(TEXT("RootEmpty")); SetRootComponent(root); laserParticle = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("LaserParticle")); laserParticle->AttachTo(RootComponent); ConstructorHelpers::FObjectFinder<UParticleSystem> particleAssets(TEXT("/Game/Particles/P_NewLaser")); laserParticle->SetTemplate(particleAssets.Object); laserSparkParticle = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("LaserSparkParticle")); laserSparkParticle->AttachTo(RootComponent); ConstructorHelpers::FObjectFinder<UParticleSystem> particleSparkAssets(TEXT("/Game/Particles/P_LaserSparks")); laserSparkParticle->SetTemplate(particleSparkAssets.Object); mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("laser emitter")); mesh->AttachTo(RootComponent); ConstructorHelpers::FObjectFinder<UStaticMesh> laserEmitterMesh(TEXT("/Game/Models/TurretGun")); mesh->SetStaticMesh(laserEmitterMesh.Object); mesh->SetCastShadow(false); mesh->SetWorldScale3D(FVector(0.3f)); ConstructorHelpers::FObjectFinder<USoundWave> laserEmitSoundFile( TEXT( "/Game/Sound/S_LaserLoop" ) ); laserEmitSound = CreateDefaultSubobject<UAudioComponent>( TEXT( "Laser Emit Sound" ) ); laserEmitSound->SetSound( laserEmitSoundFile.Object ); laserEmitSound->AttachTo( GetRootComponent() ); }
void AProjectile::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit) { // On hitting something we should turn off the "smoke trail" LaunchBlast->Deactivate(); // And Turn on the "Impact" ImpactBlast->Activate(); // Apply an Force (impulse) to the Tank ExplosionForce->FireImpulse(); // Set A dif root SetRootComponent(ImpactBlast); // Destroy the Projectile CollisionMesh->DestroyComponent(); // Apply some damage to Other Tank UGameplayStatics::ApplyRadialDamage( this, ProjectileDamage, GetActorLocation(), ExplosionForce->Radius, // for Consistancy UDamageType::StaticClass(), TArray<AActor*>() // Damage all actors ); // Set a timer to destroy this projectile after a given time FTimerHandle Timer; GetWorld()->GetTimerManager().SetTimer(Timer, this, &AProjectile::OnTimerExpire, DestroyDelay, false); }
ACSExplosive::ACSExplosive(const FObjectInitializer& Initializer) : Super(Initializer) { TouchComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Touch")); SetRootComponent(TouchComponent); TouchComponent->bGenerateOverlapEvents = true; TouchComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap); TouchComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_WorldStatic, ECollisionResponse::ECR_Ignore); TouchComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_Visibility, ECollisionResponse::ECR_Ignore); TouchComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_Camera, ECollisionResponse::ECR_Ignore); TouchComponent->SetCollisionResponseToChannel(ECollisionChannel::ECC_Projectile, ECollisionResponse::ECR_Ignore); StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh")); StaticMeshComponent->AttachTo(RootComponent); StaticMeshComponent->SetMobility(EComponentMobility::Movable); StaticMeshComponent->SetCollisionProfileName(TEXT("BlockAll")); ExplodeParticleScale = FVector(1); ExplodeRadius = 500; CenterDamage = 200; BorderDamage = 20; CenterTemperature = 0; BorderTemperature = 0; }
// Sets default values AFournoidKeeper::AFournoidKeeper() : KeeperStickDistance(500.0f), KeeperPropelDistance(100.0f), KeeperMovementSpeed(1000.0f), KeeperHoverFalloff(10.f) { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; ArrowComp = CreateDefaultSubobject<UArrowComponent>(TEXT("KeeperFacingArrow")); SetRootComponent(ArrowComp); KeeperSphereComp = CreateDefaultSubobject<USphereComponent>(TEXT("KeeperSphereComp")); KeeperSphereComp->BodyInstance.SetCollisionProfileName("OverlapAll"); KeeperSphereComp->AttachParent = ArrowComp; StaticMeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("KeeperMesh")); StaticMeshComp->SetCollisionProfileName("NoCollision"); StaticMeshComp->AttachParent = KeeperSphereComp; StaticMeshComp->bCastDynamicShadow = true; StaticMeshComp->CastShadow = true; // KeeperMovement = CreateDefaultSubobject<UMovementComponent>(TEXT("KeeperMovement")); // KeeperMovement->UpdatedComponent = KeeperSphereComp; bReplicates = true; bReplicateMovement = true; }
// Sets default values AGameObject::AGameObject( const FObjectInitializer& PCIP ) { //LOG( "%s [%s]->AGameObject::AGameObject()", *GetName(), *Name ); PrimaryActorTick.bCanEverTick = 1; ID = 0; team = 0; Pos = Zero; FollowTarget = AttackTarget = 0; RepelMultiplier = 1.f; Dead = 0; LifeTime = 0.f; MaxLifeTime = FLT_MAX; // start out with infinite lifetime DeadTime = 0.f; MaxDeadTime = CapDeadTime; vizColor = FLinearColor::MakeRandomColor(); vizSize = 10.f; IsReadyToRunNextCommand = 0; AttackReady = 0; HoldingGround = 0; DummyRoot = PCIP.CreateDefaultSubobject<USceneComponent>( this, TEXT("Dummy") ); SetRootComponent( DummyRoot ); hitBox = PCIP.CreateDefaultSubobject<UBoxComponent>( this, TEXT("HitBox") ); hitBox->AttachTo( DummyRoot ); repulsionBounds = PCIP.CreateDefaultSubobject<USphereComponent>( this, TEXT("RepulsionVolume") ); repulsionBounds->AttachTo( DummyRoot ); Grounds = 1; Untargettable = 0; //bCollideWhenPlacing = 0; GroundDestination = 0; }
AShooterProjectile::AShooterProjectile(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.TickGroup = TG_PrePhysics; SetReplicates(true); SetRemoteRoleForBackwardsCompat(ROLE_SimulatedProxy); bReplicateMovement = true; //!< スフィア SphereComp = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, "SphereComp"); if (nullptr != SphereComp) { SphereComp->InitSphereRadius(5.0f); SphereComp->AlwaysLoadOnClient = true; SphereComp->AlwaysLoadOnServer = true; SphereComp->bTraceComplexOnMove = true; //!< コリジョン SphereComp->SetCollisionObjectType(ECC_GameTraceChannel_WeaponProjectile); SphereComp->SetCollisionEnabled(ECollisionEnabled::QueryOnly); SphereComp->SetCollisionResponseToAllChannels(ECR_Ignore); SphereComp->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block); SphereComp->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Block); SphereComp->SetCollisionResponseToChannel(ECC_Pawn, ECR_Block); SetRootComponent(SphereComp); } //!< メッシュ StaticMeshComp = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, "StaticMeshComp"); if (nullptr != StaticMeshComp) { //!< メッシュ自体のコリジョンは無し StaticMeshComp->SetCollisionObjectType(ECC_WorldDynamic); StaticMeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision); StaticMeshComp->SetCollisionResponseToAllChannels(ECR_Ignore); StaticMeshComp->SetupAttachment(SphereComp); } //!< プロジェクタイル ProjectileMovementComp = ObjectInitializer.CreateDefaultSubobject<UProjectileMovementComponent>(this, "ProjectileMovementComp"); if (nullptr != ProjectileMovementComp) { ProjectileMovementComp->InitialSpeed = 2000.0f; ProjectileMovementComp->MaxSpeed = 2000.0f; ProjectileMovementComp->bRotationFollowsVelocity = true; ProjectileMovementComp->ProjectileGravityScale = 0.0f; //!< ホーミング設定 //ProjectileMovementComp->bIsHomingProjectile = true; //ProjectileMovementComp->HomingAccelerationMagnitude = ; //ProjectileMovementComp->HomingTargetComponent = nullptr; ProjectileMovementComp->SetUpdatedComponent(SphereComp); } }
// Sets default values ABaseActor::ABaseActor() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Root")); SetRootComponent(Mesh); }
// Sets default values ARotatingGear::ARotatingGear() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; Mesh = AActor::CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Gear")); SetRootComponent(Mesh); mirrored = false; running = true; }
ASrPlayerPawn::ASrPlayerPawn() { GetCollisionComponent()->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName); bAddDefaultMovementBindings = false; CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComponent")); if (CapsuleComponent) { CapsuleComponent->InitCapsuleSize(0.0f, 0.0f); CapsuleComponent->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName); CapsuleComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); CapsuleComponent->CanCharacterStepUpOn = ECB_No; CapsuleComponent->bShouldUpdatePhysicsVolume = false; CapsuleComponent->bCheckAsyncSceneOnMove = false; CapsuleComponent->SetCanEverAffectNavigation(false); CapsuleComponent->bDynamicObstacle = false; SetRootComponent(CapsuleComponent); } else { UE_LOG(LogSr, Error, TEXT("Failed to instaniate Capsule Component in %s"), *GetName()); } // Create a camera boom (pulls in towards the player if there is a collision) CameraBoomComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); if (CameraBoomComponent) { CameraBoomComponent->SetupAttachment(RootComponent); CameraBoomComponent->TargetArmLength = 30000.0f; // The camera follows at this distance behind the character CameraBoomComponent->bUsePawnControlRotation = true; // Rotate the arm based on the controller CameraBoomComponent->bDoCollisionTest = false; } else { UE_LOG(LogSr, Error, TEXT("Failed to instaniate Camera Boom Component in %s"), *GetName()); } CameraComponent = CreateDefaultSubobject<USrPlayerCameraComponent>("CameraComponent"); if (CameraComponent) { CameraComponent->SetupAttachment(CameraBoomComponent, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation CameraComponent->bUsePawnControlRotation = false; // Camera does not rotate relative to arm } else { UE_LOG(LogSr, Error, TEXT("Failed to instaniate Camera Component in %s"), *GetName()); } }
ALeafNode::ALeafNode(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { PrimaryActorTick.bCanEverTick = true; FRandomStream Rand = FRandomStream(); // The SceneComponent gives this AActor class a transform to represent it's location in World Space. SceneComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneComponent")); SceneComponent->SetMobility(EComponentMobility::Movable); SetRootComponent(SceneComponent); }
// Sets default values ACoverActor::ACoverActor() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; //Init. components SM = CreateDefaultSubobject<UStaticMeshComponent>(FName("SM")); BoxComp = CreateDefaultSubobject<UBoxComponent>(FName("BoxComp")); SetRootComponent(SM); BoxComp->SetupAttachment(SM); }
// Sets default values AWeaponPickup::AWeaponPickup() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; BoxComp = CreateDefaultSubobject<UBoxComponent>(FName("BoxComp")); SetRootComponent(BoxComp); WeaponSkeletalMesh = CreateDefaultSubobject<USkeletalMeshComponent>(FName("WeaponSkeletalMesh")); WeaponSkeletalMesh->AttachTo(GetRootComponent()); RotatingMovementComp = CreateDefaultSubobject<URotatingMovementComponent>(FName("RotatingMovementComp")); }
// Sets default values AIntermissionNode::AIntermissionNode() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; SceneComp = CreateDefaultSubobject<USceneComponent>(FName("SceneComp")); SetRootComponent(SceneComp); SMComp = CreateDefaultSubobject<UStaticMeshComponent>(FName("SMComp")); SMComp->AttachTo(SceneComp); BoxComp = CreateDefaultSubobject<UBoxComponent>(FName("BoxComp")); BoxComp->AttachTo(SceneComp); }
// Sets default values ACSCameraActor::ACSCameraActor() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; bFindCameraComponentWhenViewTarget = true; Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root")); SetRootComponent(Root); Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera")); Camera->AttachTo(RootComponent); ZoomState = ECSZoomState::Idle; FOVLerpSpeed = 45; HeightState = ECSHeightState::Stand; HeightLerpSpeed = 5; }
// // ARobotCameraActor::ARobotCameraActor // ARobotCameraActor::ARobotCameraActor( const FObjectInitializer& ObjectInitializer ) : Super( ObjectInitializer ) { PrimaryActorTick.bCanEverTick = true; MinArmLength = 500.0f; MaxArmLength = 1000.0f; BoundsScale = 1.25f; ExtrapolateSpeed = 10.0f; LookAtSceneComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>( this, TEXT( "LookAtSceneComponent" ) ); SetRootComponent( LookAtSceneComponent ); SpringArmComponent = ObjectInitializer.CreateDefaultSubobject<USpringArmComponent>( this, TEXT( "SpringArmComponent" ) ); SpringArmComponent->AttachTo( LookAtSceneComponent ); CameraComponent = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>( this, TEXT( "CameraComponent" ) ); CameraComponent->AttachTo( SpringArmComponent ); }
void AItemPickup::SetAsSkeletalMeshPickup_Implementation() { // Destroy Extra Component if (Mesh)Mesh->DestroyComponent(); // Attach Trigger to Skeletal Mesh Component TriggerSphere->AttachTo(SkeletalMesh, NAME_None, EAttachLocation::SnapToTarget); // Set Its Properties SkeletalMesh->SetMobility(EComponentMobility::Movable); SkeletalMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Block); SkeletalMesh->SetCollisionEnabled(ECollisionEnabled::PhysicsOnly); // Set It as Root SetRootComponent(SkeletalMesh); // Enable Replicattion of Its Movement SetReplicateMovement(true); }
// Sets default values ASprungWheel::ASprungWheel() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.TickGroup = TG_PostPhysics; MassWheelConstraint = CreateDefaultSubobject<UPhysicsConstraintComponent>(FName("MassWheelConstraint")); SetRootComponent(MassWheelConstraint); Axle = CreateDefaultSubobject<USphereComponent>(FName("Axle")); Axle->SetupAttachment(MassWheelConstraint); Wheel = CreateDefaultSubobject<USphereComponent>(FName("Wheel")); Wheel->SetupAttachment(Axle); AxleWheelConstraint = CreateDefaultSubobject<UPhysicsConstraintComponent>(FName("AxleWheelConstraint")); AxleWheelConstraint->SetupAttachment(Axle); }
// Sets default values ABomb::ABomb() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; SphereComp = CreateDefaultSubobject<USphereComponent>(FName("SphereComp")); SetRootComponent(SphereComp); SM = CreateDefaultSubobject<UStaticMeshComponent>(FName("SM")); SM->SetupAttachment(SphereComp); ProjectileMovementComp = CreateDefaultSubobject<UProjectileMovementComponent>(FName("ProjectileMovementComp")); ProjectileMovementComp->bShouldBounce = true; //Since we need to replicate some functionality //for this actor, we need to mark it as true SetReplicates(true); }
void AProjectile::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit) { LaunchBlast->Deactivate(); ImpactBlast->Activate(); ExplosionForce->FireImpulse(); SetRootComponent(ImpactBlast); CollisionMesh->DestroyComponent(); UGameplayStatics::ApplyRadialDamage( this, ProjectileDamage, GetActorLocation(), ExplosionForce->Radius, UDamageType::StaticClass(), TArray<AActor*>() // don't ignore any actors ); auto Timer = FTimerHandle(); GetWorld()->GetTimerManager().SetTimer(Timer, this, &AProjectile::OnTimerExpire, DestroyDelay, false); }
// Sets default values AProjectile::AProjectile() { // alternatively we could have added this in BPs ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(FName("Projectile Movement")); ProjectileMovement->bAutoActivate = false; CollisionMesh = CreateDefaultSubobject<UStaticMeshComponent>(FName("Collision Mesh")); SetRootComponent(CollisionMesh); CollisionMesh->SetNotifyRigidBodyCollision(true); // set sensible defaults CollisionMesh->SetVisibility(true); LaunchBlast = CreateDefaultSubobject<UParticleSystemComponent>(FName("Launch Blast")); LaunchBlast->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); ImpactBlast = CreateDefaultSubobject<UParticleSystemComponent>(FName("Impact Blast")); ImpactBlast->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); ImpactBlast->bAutoActivate = false; ExplosionForce = CreateDefaultSubobject<URadialForceComponent>(FName("Explosion")); ExplosionForce->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); }
// Sets default values AProjectile::AProjectile() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = false; CollisionMesh = CreateDefaultSubobject<UStaticMeshComponent>(FName("Collision Mesh")); SetRootComponent(CollisionMesh); CollisionMesh->SetNotifyRigidBodyCollision(true); CollisionMesh->SetVisibility(false); LaunchBlast = CreateDefaultSubobject<UParticleSystemComponent>(FName("Launch Blast")); LaunchBlast->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(FName("Projectile Movement")); ProjectileMovement->bAutoActivate = false; ImpactBlast = CreateDefaultSubobject<UParticleSystemComponent>(FName("Impact Blast")); ImpactBlast->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); ImpactBlast->bAutoActivate = false; ExplosionForce = CreateDefaultSubobject<URadialForceComponent>(FName("Explosion Force")); ExplosionForce->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); }
void AActor::OnConstruction(const FTransform& Transform) { check(!IsPendingKill()); check(!HasAnyFlags(RF_BeginDestroyed|RF_FinishDestroyed)); // Generate the parent blueprint hierarchy for this actor, so we can run all the construction scripts sequentially TArray<const UBlueprintGeneratedClass*> ParentBPClassStack; const bool bErrorFree = UBlueprintGeneratedClass::GetGeneratedClassesHierarchy(GetClass(), ParentBPClassStack); // If this actor has a blueprint lineage, go ahead and run the construction scripts from least derived to most if( (ParentBPClassStack.Num() > 0) ) { if( bErrorFree ) { FEditorScriptExecutionGuard ScriptGuard; // Prevent user from spawning actors in User Construction Script TGuardValue<bool> AutoRestoreISCS(GetWorld()->bIsRunningConstructionScript, true); for( int32 i = ParentBPClassStack.Num() - 1; i >= 0; i-- ) { const UBlueprintGeneratedClass* CurrentBPGClass = ParentBPClassStack[i]; check(CurrentBPGClass); if(CurrentBPGClass->SimpleConstructionScript) { CurrentBPGClass->SimpleConstructionScript->ExecuteScriptOnActor(this, Transform); } // Now that the construction scripts have been run, we can create timelines and hook them up CurrentBPGClass->CreateTimelinesForActor(this); } #if WITH_EDITOR bool bDoUserConstructionScript; GConfig->GetBool(TEXT("Kismet"), TEXT("bTurnOffEditorConstructionScript"), bDoUserConstructionScript, GEngineIni); if (!GIsEditor || !bDoUserConstructionScript) #endif { // Then run the user script, which is responsible for calling its own super, if desired ProcessUserConstructionScript(); } // Bind any delegates on components ((UBlueprintGeneratedClass*)GetClass())->BindDynamicDelegates(this); // We have a BP stack, we must have a UBlueprintGeneratedClass... } else { // Disaster recovery mode; create a dummy billboard component to retain the actor location // until the compile error can be fixed if (RootComponent == NULL) { UBillboardComponent* BillboardComponent = NewObject<UBillboardComponent>(this); BillboardComponent->SetFlags(RF_Transactional); BillboardComponent->bCreatedByConstructionScript = true; #if WITH_EDITOR BillboardComponent->Sprite = (UTexture2D*)(StaticLoadObject(UTexture2D::StaticClass(), NULL, TEXT("/Engine/EditorResources/BadBlueprintSprite.BadBlueprintSprite"), NULL, LOAD_None, NULL)); #endif BillboardComponent->SetRelativeTransform(Transform); SetRootComponent(BillboardComponent); FinishAndRegisterComponent(BillboardComponent); } } } }
void AActor::ExecuteConstruction(const FTransform& Transform, const FComponentInstanceDataCache* InstanceDataCache, bool bIsDefaultTransform) { check(!IsPendingKill()); check(!HasAnyFlags(RF_BeginDestroyed|RF_FinishDestroyed)); // ensure that any existing native root component gets this new transform // we can skip this in the default case as the given transform will be the root component's transform if (RootComponent && !bIsDefaultTransform) { RootComponent->SetWorldTransform(Transform); } // Generate the parent blueprint hierarchy for this actor, so we can run all the construction scripts sequentially TArray<const UBlueprintGeneratedClass*> ParentBPClassStack; const bool bErrorFree = UBlueprintGeneratedClass::GetGeneratedClassesHierarchy(GetClass(), ParentBPClassStack); // If this actor has a blueprint lineage, go ahead and run the construction scripts from least derived to most if( (ParentBPClassStack.Num() > 0) ) { if( bErrorFree ) { // Prevent user from spawning actors in User Construction Script TGuardValue<bool> AutoRestoreISCS(GetWorld()->bIsRunningConstructionScript, true); for( int32 i = ParentBPClassStack.Num() - 1; i >= 0; i-- ) { const UBlueprintGeneratedClass* CurrentBPGClass = ParentBPClassStack[i]; check(CurrentBPGClass); if(CurrentBPGClass->SimpleConstructionScript) { CurrentBPGClass->SimpleConstructionScript->ExecuteScriptOnActor(this, Transform, bIsDefaultTransform); } // Now that the construction scripts have been run, we can create timelines and hook them up CurrentBPGClass->CreateComponentsForActor(this); } // If we passed in cached data, we apply it now, so that the UserConstructionScript can use the updated values if(InstanceDataCache) { InstanceDataCache->ApplyToActor(this, ECacheApplyPhase::PostSimpleConstructionScript); } #if WITH_EDITOR bool bDoUserConstructionScript; GConfig->GetBool(TEXT("Kismet"), TEXT("bTurnOffEditorConstructionScript"), bDoUserConstructionScript, GEngineIni); if (!GIsEditor || !bDoUserConstructionScript) #endif { // Then run the user script, which is responsible for calling its own super, if desired ProcessUserConstructionScript(); } // Since re-run construction scripts will never be run and we want to keep dynamic spawning fast, don't spend time // determining the UCS modified properties in game worlds if (!GetWorld()->IsGameWorld()) { for (UActorComponent* Component : GetComponents()) { if (Component) { Component->DetermineUCSModifiedProperties(); } } } // Bind any delegates on components ((UBlueprintGeneratedClass*)GetClass())->BindDynamicDelegates(this); // We have a BP stack, we must have a UBlueprintGeneratedClass... // Apply any cached data procedural components // @TODO Don't re-apply to components we already applied to above if (InstanceDataCache) { InstanceDataCache->ApplyToActor(this, ECacheApplyPhase::PostUserConstructionScript); } } else { // Disaster recovery mode; create a dummy billboard component to retain the actor location // until the compile error can be fixed if (RootComponent == NULL) { UBillboardComponent* BillboardComponent = NewObject<UBillboardComponent>(this); BillboardComponent->SetFlags(RF_Transactional); BillboardComponent->CreationMethod = EComponentCreationMethod::SimpleConstructionScript; #if WITH_EDITOR BillboardComponent->Sprite = (UTexture2D*)(StaticLoadObject(UTexture2D::StaticClass(), NULL, TEXT("/Engine/EditorResources/BadBlueprintSprite.BadBlueprintSprite"), NULL, LOAD_None, NULL)); #endif BillboardComponent->SetRelativeTransform(Transform); SetRootComponent(BillboardComponent); FinishAndRegisterComponent(BillboardComponent); } } } GetWorld()->UpdateCullDistanceVolumes(this); // Now run virtual notification OnConstruction(Transform); }