Advertisement
cgprojectsfx

Worker CPP

Jun 22nd, 2019
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3.  
  4. #include "Populate_CPP_Worker.h"
  5.  
  6.  
  7. // Sets default values
  8. APopulate_CPP_Worker::APopulate_CPP_Worker()
  9. {
  10.     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  11.     PrimaryActorTick.bCanEverTick = true;
  12.  
  13. }
  14.  
  15. // Called when the game starts or when spawned
  16. void APopulate_CPP_Worker::BeginPlay()
  17. {
  18.     Super::BeginPlay();
  19.    
  20. }
  21.  
  22. // Called every frame
  23. void APopulate_CPP_Worker::Tick(float DeltaTime)
  24. {
  25.     Super::Tick(DeltaTime);
  26.  
  27. }
  28.  
  29. // Called every frame
  30. void APopulate_CPP_Worker::CreateWorkerInstance()
  31. {  
  32.     // Get world to spawn
  33.     UWorld* world = GetWorld();
  34.  
  35.     // Spawn Parameter
  36.     FActorSpawnParameters spawnParams;
  37.  
  38.     // Set Owner to This
  39.     //spawnParams.Owner = this;
  40.     spawnParams.SpawnCollisionHandlingOverride=ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
  41.  
  42.     // User Passed transformation
  43.     InstancedActor = world->SpawnActor<AActor>(Transformation.GetLocation(), FRotator::ZeroRotator, spawnParams);
  44.  
  45.     if(InstancedActor)
  46.     {
  47.             // Create Object
  48.             InstancedStaticMeshComponent = NewObject<UInstancedStaticMeshComponent>(InstancedActor);
  49.  
  50.             // Attach to actor
  51.             InstancedStaticMeshComponent->AttachTo(InstancedActor->GetRootComponent());
  52.  
  53.             // Set Static Mesh
  54.             InstancedStaticMeshComponent->SetStaticMesh(StaticMesh);
  55.  
  56.             // Register
  57.             InstancedStaticMeshComponent->RegisterComponent();
  58.  
  59.             if(InstancedStaticMeshComponent)
  60.             {
  61.                 PopulateSpawner->HandleWorkerResponse(this, true, InstancedActor);
  62.             }else
  63.             {
  64.                 PopulateSpawner->HandleWorkerResponse(this, false, nullptr);
  65.             }
  66.     }
  67. }
  68.  
  69. void APopulate_CPP_Worker::AddInstance()
  70. {
  71.      Transformation.DebugPrint();
  72.  
  73.     // If Instance is created
  74.     if(InstancedStaticMeshComponent)
  75.     {  
  76.         // Add Instance to World Space
  77.         InstancedStaticMeshComponent->AddInstanceWorldSpace(Transformation);
  78.        
  79.         // Handle Worker Response
  80.         PopulateSpawner->HandleWorkerResponse(this, true, InstancedActor);
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement