Actor Subclass not updating it's default values

Hi there,

I ran into a serious problem at the weekend and I don’t understand why it happens. The issue is, whenever I try to change to default value in a actor subclass via reference from another class It don’t update the actors variable. It actually has the correct value in the end of the setter, however if I output it in the tick it still has it’s default value.

I tested it with 4.10 (VS2013) and 4.12.5 (VS2015) on 2 different and in 2 projects, but the result is always the same.
I can set the value inside the tick itself, so in theory I can store a reference to the “calling” component class in GameMode and let the setter take it from there inside the tick function (even set pointer references in the actor class are not set, outside the setter…also it make no difference if I make in FORCEINLINE or not)…however I want to avoid such “hacky” solution if possibe. This is driving me crazy since I see nothing wrong.

Code: h

#pragma once

#include "GameFramework/Actor.h"
#include "Engine.h"
#include "LockStudio.generated.h"

UCLASS()
class LOCKPICKING_API ALockStudio : public AActor
{
	GENERATED_BODY()
	
public:	
	/** Sets default values for this actor's properties */
	ALockStudio(const FObjectInitializer& ObjectInitializer);

	/** Called every frame */
	virtual void Tick( float DeltaSeconds ) override;

	/** Set Lockpick Position */
	FORCEINLINE void SetLockpickPosition(float NewPos)
	{
		LockpickPosition = NewPos;
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("LockpickPosition is: %f"), LockpickPosition));
	}

private:

	/** Lockpick Position */
	float LockpickPosition;
};

Code: cpp

#include "Lockpicking.h"
#include "LockStudio.h"


/* Sets default values for this actor's properties */
ALockStudio::ALockStudio(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
 	// 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;

	LockpickPosition = .0f;
}


/* Called every frame */
void ALockStudio::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::Printf(TEXT("LockpickPosition is: %f"), LockpickPosition));
}

The cyan value is from the tick, the green one from the setter.

https://dl.dropboxusercontent.com/u/14494026/ErrorActorClass.jpg

I can provide the project for investigation to epic if needed.

Thanks in advance

@Mastersmith98: Yes, I inherit a blueprint from the class, but just as reference to spawn it in the level once lockpicking starts. However the BP doesn’t have access to any variables, it’s basically just there to be able to adjust lock and picking tool inside the editor. I already did a couple project refreshes, unfortunally the problem is persist. It’s a really nasty issue

I ran into a similar problem myself. First, are you deriving a blueprint from this class? If so, the default values set in the blueprints override whatever you put in the classes(sp?) constructor.

If this doesn’t work for you, try to a complete refresh of your project (delete the binaries, intermediate, solution, etc., any generated file) and right click your uproject → generate solution, and rebuild the project.

Hm, you’re right. Possibly try creating another blueprint reference and seeing if that error persists. Otherwise I’d suspect that your constructor might not be called for some reason. Also, just as an aside, I don’t believe you have to use the FObjectInitializer constructor anymore. Just a vanilla c++ one will do.

Gotcha, well best of luck! I hope someone can come along with a good solution for you.

Thanks, I’ll try with a second BP, but I doubt it will fix it, since I already did a complete clean setup for testing.
In the full class I need the FObjectInitializer because I create DefaultSubobjects for Static Meshes, Scenecapture Components and Lights.

For finding the issue I stripped basically everything from the class to track down the source of the issue…but as you see it is still persist in an even almost empty class

Hey LestatDeLioncourt-

Where exactly are you calling the setter from? How are you referencing your variable from another class? In my local test when I call LockStudioRef->SetLockpickPosition(45.45); the value printed on tick from ALockStudio (cyan text) is updated as expected. If you have a sample project with the behavior described, please provide it for additional information.

Hi, thanks for the fast reply.

I call it from the pointer to the spawned actor.

It seems to be fixed now after I recompiled the engine source together with the project (I made a complete rebuild). I have no idea what was causing the issue, but it seems it was a local problem. Even if I test it on the other it works now.