x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Can't Spawn Static Mesh Component

I am trying to spawn a grid but nothing happens.Not even a compile error.

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "GridGenerator.h"
 #include "Components/StaticMeshComponent.h"
 #include "ConstructorHelpers.h"
 // Sets default values
 AGridGenerator::AGridGenerator()
 {
      // 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;
     size = 16;
     sum = size * size;
     offsetAmount = 65;
     
     for (int i = 0; i < sum; i++) {
         if (sum % size == 0) {
             FVector temp;
             temp.X = sum+offsetAmount;
             temp.Y = offsetAmount;
             temp.Z = 0;
             offsetVector = offsetVector+temp;
 
             ReactiveFloor(worldLocation);
 
             MeshArray[i] = Mesh;
 
             offsetVector.X = offsetVector.X + offsetAmount;
         }
         else {
             ReactiveFloor(worldLocation);
 
             MeshArray[i] = Mesh;
 
             offsetVector.X = offsetVector.X + offsetAmount;
         }
     }
 }
 
 UStaticMeshComponent* AGridGenerator::SpawnMesh(FVector offsetVector)
 {
     UStaticMeshComponent* Grid = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Grid"));
     Grid->SetupAttachment(RootComponent);
 
     static ConstructorHelpers::FObjectFinder<UStaticMesh>GridAsset(TEXT("/Game/Models-Textures/StaticMeshes/Plane_64x64.uasset"));
 
     Grid->SetStaticMesh(GridAsset.Object);
     Grid->SetRelativeLocation(offsetVector);
     Grid->SetWorldScale3D(FVector(1.f));
     worldLocation = offsetVector;
     return Grid;
 }
 
 void AGridGenerator::ReactiveFloor(FVector worldLocation) {
     FCollisionQueryParams RV_TraceParams = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, this);
     RV_TraceParams.bTraceComplex = true;
     RV_TraceParams.bTraceAsyncScene = true;
     RV_TraceParams.bReturnPhysicalMaterial = false;
 
     FHitResult RV_Hit(ForceInit);
 
     GetWorld()->LineTraceSingleByChannel(RV_Hit, worldLocation + (FVector(0, 0, 2000)), worldLocation - (FVector(0, 0, 2000)), ECC_EngineTraceChannel1);
     FVector temp2;
     temp2.X = worldLocation.X;
     temp2.Y = worldLocation.Y;
     temp2.Z = RV_Hit.ImpactPoint.Z;
     FRotator tempR;
     tempR.Pitch = (RV_Hit.ImpactNormal.X * 45);
     tempR.Roll = (RV_Hit.ImpactNormal.Y * 45);
 
     SetActorLocationAndRotation(temp2, tempR);
 }
Product Version: UE 4.21
Tags:
more ▼

asked Jan 19 '19 at 09:31 PM in C++ Programming

avatar image

Esamy
6

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hey,

Do you try to spawn meshes at runtime, because CreateDefaultSubObject and Construction helper works only at Construction Time (eg. when engine starting)?

Also maybe im wrong but as i see you're not calling "SpawnMesh" function? but anyway i think you try to spawn grid runtime so CreateDefaultSubObject and FConstruction helper wont work. Use NewObject and RegisterComponent instead.

more ▼

answered Jan 23 '19 at 08:36 AM

avatar image

AmphDev
1.5k 15 9 33

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question