Announcement

Collapse
No announcement yet.

Spawn Component instead of ProjectileClass

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    You might be looking for:

    In constructor:
    Code:
    UBoxComponent* boxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComponent"));
    or most other places
    Code:
    UBoxComponent* boxComponent = NewObject<UBoxComponent>(this, UBoxComponent::StaticClass());
    boxComponent->RegisterComponent();
    Last edited by Telimaktar; 10-07-2019, 02:38 AM.

    Leave a comment:


  • started a topic Spawn Component instead of ProjectileClass

    Spawn Component instead of ProjectileClass

    Hi,

    How to spawn component like BoxComponent or other component with my code. The main reason is because I need if component hit "Head" with boxcomponent then display text (check above). This code works but display projectileclass.

    my code:

    AActor* MyActor = GetRootComponent()->GetOwner();
    if (MyActor && ProjectileClass)
    {



    FVector EyeLocation;
    FRotator EyeRotation;
    MyActor->GetActorEyesViewPoint(EyeLocation, EyeRotation);

    FVector ShotDirection = EyeRotation.Vector();
    FVector TraceEnd = EyeLocation + (ShotDirection * 10000);

    FCollisionQueryParams QueryParams;
    QueryParams.AddIgnoredActor(MyActor);
    QueryParams.AddIgnoredActor(this);
    QueryParams.bTraceComplex = true;
    QueryParams.bReturnPhysicalMaterial = true;

    FVector MuzzleLocation = GetMesh()->GetSocketLocation("headSocket");


    FHitResult Hit;
    if (GetWorld()->LineTraceSingleByChannel(Hit, EyeLocation, TraceEnd, ECC_Visibility, QueryParams))
    {
    //UE_LOG(LogTemp, Warning, TEXT("Your message"));

    AActor* HitActor = Hit.GetActor();

    UGameplayStatics::ApplyPointDamage(HitActor, 20.0f, ShotDirection, Hit, MyActor->GetInstigatorController(), this, DamageType);
    }



    FActorSpawnParameters ActorSpawnParams;
    ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
    GetWorld()->SpawnActor<AActor>(ProjectileClass, MuzzleLocation, EyeRotation, ActorSpawnParams);




    EPhysicalSurface SurfaceType = UPhysicalMaterial:etermineSurfaceType(Hit.PhysMaterial.Get());



    if (SurfaceType == Head)
    {
    UE_LOG(LogTemp, Warning, TEXT("Test"));
    }
Working...
X