Base Color not updating for C++ derived class in level editor

Hello,

I have a base class called PowerUp where I use a dynamic material instance to change the base color in derived classes, such as GrowthPowerUp. To do so, in the constructor of the derived classes I simply call a function I defined in the base class, PowerUp::SetBaseColor()

When I compile the code, everything seems to be as expected: in the content browser, I can see that PowerUp and GrowthPowerUp classes have the same shape but different base colors, and also when I include them in the level:

However, as soon as I recompile the C++ project, the different color in GrowthPowerUp does not appear anymore in the editor, although it is still visible in the content browser:

The relevant code in the header and source files is shown below. I don’t know if I am doing something wrong to set the base color in the derived classes, but nevertheless the change in visualization before and after recompiling must be some sort of bug in the level editor. When the GrowthPowerUp instances are spawned during the game with GetWorld()->SpawnActor(), they appear with the expected color again.

I am using unreal engine 4.7.6 in Windows 7 from the Epic Games Launcher, specifically verison 4.7.6-2513093+++depot+UE4-Releases+4.7

PowerUp.h:

#pragma once

#include "GameFramework/Actor.h"
#include "PowerUp.generated.h"

UCLASS()
class SNAKE_API APowerUp : public AActor
{
	GENERATED_BODY()

protected:
	/* BodyMesh component for the clickable block */
	UPROPERTY(Category = Body, VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
	class UStaticMeshComponent* BodyMesh;

public:	
	// Sets default values for this actor's properties
	APowerUp();

	UFUNCTION()
	void SetBaseColor(const FLinearColor BaseColor);
};

PowerUp.cpp:

#include "Snake.h"
#include "PowerUp.h"
#include "GrowthPowerUp.h"

// Sets default values
APowerUp::APowerUp()
{
	// Structure to hold one-time initialization
	struct FConstructorStatics
	{
		ConstructorHelpers::FObjectFinderOptional<UStaticMesh> PowerUpMesh;
		FConstructorStatics()
			: PowerUpMesh(TEXT("/Game/Meshes/PowerUp.PowerUp"))
		{
		}
	};
	static FConstructorStatics ConstructorStatics;

	// Create static mesh component
	BodyMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PowerUp0"));
	BodyMesh->SetStaticMesh(ConstructorStatics.PowerUpMesh.Get());
	BodyMesh->SetRelativeLocation(FVector(0.f, 0.f, 0.f));
	BodyMesh->SetRelativeScale3D(FVector(1.f, 1.f, 1.f));
	BodyMesh->CreateAndSetMaterialInstanceDynamic(0);
	BodyMesh->SetCollisionProfileName("PowerUp");
	BodyMesh->bGenerateOverlapEvents = true;
	RootComponent = BodyMesh;
}

void APowerUp::SetBaseColor(const FLinearColor BaseColor)
{
	UMaterialInstanceDynamic* Material = (UMaterialInstanceDynamic*)BodyMesh->GetMaterial(0);
	Material->SetVectorParameterValue(FName(TEXT("BaseColor")), BaseColor);
}

GrowthPowerUp.h:

#include "PowerUp.h"
#include "GrowthPowerUp.generated.h"

UCLASS()
class SNAKE_API AGrowthPowerUp : public APowerUp
{
	GENERATED_BODY()
	
public:
	AGrowthPowerUp();

	//The amount of body parts that this PowerUp will make the snake increase
	uint32 DeltaSize;
};

GrowthPowerUp.cpp:

#include "Snake.h"
#include "GrowthPowerUp.h"
#include "SnakeHead.h"

AGrowthPowerUp::AGrowthPowerUp()
	: Super()
{
	SetBaseColor(FLinearColor(0.9f, 0.1f, 0.1f));
	DeltaSize = 5; 
}

Material definition:

Hi FernAndr -

I am not experiencing the same behavior that you are describing above. I have included a sample project below for you to look at. I may be doing something slightly different than you are. All you need to do when you unzip the project is to right click the Project File and Generate Solution Files. Feel free to make any changes to make it behave like you are experiencing and upload a version when you are done in the same manner.

Thank You

Eric Ketchum

Hi Eric,

Sorry, I cannot see any attached project, has it been uploaded? I can also prepare a reduced version of my project to upload it too, in case the issue is related to the particular contents I am using and not the code itself.

Thanks,

Fernando

My Apologies, Here is the Sample Project

Sample Project

Hi Eric,

I have tried the sample project and I am obtaining the same behaviour:

Just to clarify, for this to happen, the code must be rebuilt, i.e. it will not occur by clicking compile in the ue4 when it is already compiled. The “Rebuild Solution” option in visual studio triggers this, or also simply compiling after the smallest change in the soruce code (such as a space).

If it is of any help, my visual studio version is: Visual Studio Community 2013, version 12.0.31101.00 Update 4, and my OS is Windows 7 Home Premium

Hi -

Just an update, we are able to see the issue in the project. Thank you for the additional information that helped clear it up. Currently we are tracking down the resultant cause of that and will post as soon as we know something more.

Thank You

Eric Ketchum