I am trying to set a material on to this static mesh and for some reason the debugger is acting up.
#include "DestroyedActor3.h"
#include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h"
ADestroyedActor3::ADestroyedActor3()
{
Mesh3 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
RootComponent = Mesh3;
static ConstructorHelpers::FObjectFinder<UMaterialInterface>Greener
(TEXT("Material'/Game/BLUEPRINTS/MATERIALS/Green.Greener'"));
if (Greener.Succeeded())
{
NewestColor = Greener.Object;
}
}
void ADestroyedActor3::Color3()
{
Super::BeginPlay();
This is where it is acting up. Mesh3() is the debuggers issue saying "parenthesis after apparent call must be a pointer to type."
Mesh3()->SetMaterial(0, NewestColor);
}
Here is the .h file
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "DestroyedActor.h"
#include "Components/SkeletalMeshComponent.h"
#include "Components/StaticMeshComponent.h"
#include "DestroyedActor3.generated.h"
/**
*
*/
UCLASS()
class FPSGAME_API ADestroyedActor3 : public ADestroyedActor
{
GENERATED_BODY()
protected:
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "C++", meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* Mesh3;
ADestroyedActor3();
UPROPERTY(EditAnywhere BlueprintReadWrite, Category = "C++", meta = (AllowPrivateAccess = "true"))
class UMaterialInterface* NewestColor;
int Points = -10;
UFUNCTION()
void Color3();
};
Here is the main c++ class not the derived c++ class. Here below is the .cpp.
#include "DestroyedActor.h"
#include "Components/StaticMeshComponent.h"
#include "Kismet/KismetMathLibrary.h"
#include "TimerManager.h"
// Sets default values
ADestroyedActor::ADestroyedActor()
{
// 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("Mesh"));
RootComponent = Mesh;
MaxDelay = 20.0f;
MinDelay = 15.0f;
}
// Called when the game starts or when spawned
void ADestroyedActor::BeginPlay()
{
Super::BeginPlay();
Delay = FMath::FRandRange(MaxDelay, MinDelay);
GetWorldTimerManager().SetTimer(DeathTimer, this,
&ADestroyedActor::Blast, Delay, true, 10.0f);
}
int ADestroyedActor::Score()
{
return Points;
}
// Called every frame
void ADestroyedActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector NewLocation = GetActorLocation();
if (NewLocation.Y > 1000.0f) {
BMove = false;
}
else if (NewLocation.Y < -1000.0f) {
BMove = true;
}
float factor = (BMove ? 200.f : -200.f);
NewLocation.Y += factor * DeltaTime;
SetActorLocation(NewLocation);
}
void ADestroyedActor::Blast()
{
Destroy();
}
Here is the .h file for the main .cpp class…
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/StaticMeshComponent.h"
#include "DestroyedActor.generated.h"
UCLASS()
class FPSGAME_API ADestroyedActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ADestroyedActor();
UFUNCTION()
int Score();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void Blast();
UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* Mesh;
UPROPERTY(EditAnywhere)
UMaterialInterface* Material;
UPROPERTY(EditAnywhere)
float MaxMove;
UPROPERTY(EditAnywhere)
int Points = 10;
UPROPERTY(EditAnywhere, Category = "Death", meta = (AllowPrivateAccess = "true"))
float MaxDelay;
UPROPERTY(EditAnywhere, Category = "Death", meta = (AllowPrivateAccess = "true"))
float MinDelay;
UPROPERTY(EditAnywhere, Category = "StartLocation")
FVector StartLocation;
UPROPERTY(EditAnywhere, Category = "SecondStartLocation")
FVector SecondStartLocation;
float ElapsedOutOfPlayTime = 0.0f;
int8 dir = 1;
bool BMove = true;
float Delay;
FTimerHandle DeathTimer;
};