CreateAndSetMaterialInstanceDynamic(in c++) doesn't work when using a blueprint derived from that class

So I modified the rolling ball class that comes as the default pawn in the Rolling template. What I added was the ability to change the ball’s color when you jump. I’m using 4.7.0 preview 5. Here’s my code:



UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Ball, meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* Ball;

class UMaterialInstanceDynamic* DynamicMaterial;

.cpp (in constructor)

DynamicMaterial = Ball->CreateAndSetMaterialInstanceDynamic(0);

in Tick() I use:

float WhateverValue = 0.5;
DynamicMaterial->SetScalarParameterValue(TEXT("blendColor"), WhateverValue);

(for example) to change the material’s values. This works perfectly when I just use the plain c++ class as the default pawn, but when I create a blueprint derived from this class, the color doesn’t change. After a bit of looking I found that if you pause the game while using the plain c++ pawn and check Ball’s material it shows as “MaterialInstanceDynamic”, exactly what I want. But when I check it when using the blueprint pawn, it comes up with the same material as it has set by default. This leads me to believe that the line:

DynamicMaterial = Ball->CreateAndSetMaterialInstanceDynamic(0);

is not working when using a blueprint. Any ideas why? Maybe I need a UPROPERTY() macro on DynamicMaterial? All the rest of the class functionality works in the blueprint, but not the MaterialInstanceDynamic. Am I being dumb or is this a bug? Thanks in advance for any help!