I am having some trouble when trying to reference a StaticMeshComponent from a Blueprint. In short what I am trying to do is change the parameter of one of the materials, that part works fine. But when I try to then apply the material to the mesh I crash, I did now add in a check for my pointer and I am not crashing anymore but I am not sure what I am doing wrong exactly.
.h
// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "VLight.generated.h"
/**
*
*/
UMaterialInstanceDynamic* LightMID;
UCLASS()
class AVLight : public AActor
{
GENERATED_UCLASS_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Materials)
UMaterialInterface* Base_Material;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Meshes)
UStaticMeshComponent* VaMesh;
public:
virtual void PostInitializeComponents() OVERRIDE;
};
.cc
// Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
#include "MyGamemode.h"
#include "VLight.h"
AVLight::AVLight(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
void AVLight::PostInitializeComponents()
{
Super::PostInitializeComponents();
LightMID = UMaterialInstanceDynamic::Create(Base_Material, this);
LightMID->SetVectorParameterValue(FName(TEXT("Colour")), FLinearColor(1000,0,0,1));
//For Testing only
If(!VaMesh)return;
VaMesh->SetMaterial(1, LightMID);//Crashes
}