Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "Populate_CPP_Worker.h"
- // Sets default values
- APopulate_CPP_Worker::APopulate_CPP_Worker()
- {
- // 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;
- }
- // Called when the game starts or when spawned
- void APopulate_CPP_Worker::BeginPlay()
- {
- Super::BeginPlay();
- }
- // Called every frame
- void APopulate_CPP_Worker::Tick(float DeltaTime)
- {
- Super::Tick(DeltaTime);
- }
- // Called every frame
- void APopulate_CPP_Worker::CreateWorkerInstance()
- {
- // Get world to spawn
- UWorld* world = GetWorld();
- // Spawn Parameter
- FActorSpawnParameters spawnParams;
- // Set Owner to This
- //spawnParams.Owner = this;
- spawnParams.SpawnCollisionHandlingOverride=ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
- // User Passed transformation
- InstancedActor = world->SpawnActor<AActor>(Transformation.GetLocation(), FRotator::ZeroRotator, spawnParams);
- if(InstancedActor)
- {
- // Create Object
- InstancedStaticMeshComponent = NewObject<UInstancedStaticMeshComponent>(InstancedActor);
- // Attach to actor
- InstancedStaticMeshComponent->AttachTo(InstancedActor->GetRootComponent());
- // Set Static Mesh
- InstancedStaticMeshComponent->SetStaticMesh(StaticMesh);
- // Register
- InstancedStaticMeshComponent->RegisterComponent();
- if(InstancedStaticMeshComponent)
- {
- PopulateSpawner->HandleWorkerResponse(this, true, InstancedActor);
- }else
- {
- PopulateSpawner->HandleWorkerResponse(this, false, nullptr);
- }
- }
- }
- void APopulate_CPP_Worker::AddInstance()
- {
- Transformation.DebugPrint();
- // If Instance is created
- if(InstancedStaticMeshComponent)
- {
- // Add Instance to World Space
- InstancedStaticMeshComponent->AddInstanceWorldSpace(Transformation);
- // Handle Worker Response
- PopulateSpawner->HandleWorkerResponse(this, true, InstancedActor);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement