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