Set Default Values in a blueprint

Hello guys,
i want to change the default values of an actor component in a blueprint. I tried to access the value by using these lines:

Cast<UTransformSaver>(GetClass()->GetDefaultObject())->TRS = this->TRS;

UTransformSaver is my actor component and TRS a FTransform variable. When i do the above, it changes the value but i have some issues:

  1. It changes the values for ALL my UTransformSaver Actor Components
  2. When i close the editor it resets it values.

Any ideas for the above? It would help alot because i am stuck right now…

You can change the default values of a component in a blueprint by changing the values of the properties in the native class of that component. I assume you created a custom actor component in c++ and you added it your blueprint. Can post your .h .cpp code of that component?
Tip: You should change that value in the .cpp, in the constructor function of your actor component.
Also: The code you posted, where exactly is written? In which file?

Hello Stalgom,
So, this is a UActorComponent made in cpp as you said.
I put this actor component to a blueprint that I want.
The code is pretty simple:
the .h file
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "TransformSaver.generated.h"


UCLASS(ClassGroup=(oramaVR), meta=(BlueprintSpawnableComponent) )
class SAMPLEAPP_API UTransformSaver : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UTransformSaver();
	UPROPERTY(EditAnywhere,Category="OramaVR")
	FTransform TRS;
	UFUNCTION(CallInEditor,Category="OramaVR")
	void SaveTransform();
protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

the .cpp file:

// Fill out your copyright notice in the Description page of Project Settings.


#include "TransformSaver.h"

#include "ComponentUtils.h"
#include "ConstructorHelpers.h"
#include "KismetEditorUtilities.h"
#include "Util/Orama_Util.h"

// Sets default values for this component's properties
UTransformSaver::UTransformSaver()
{
	PrimaryComponentTick.bCanEverTick = false;
	
}


void UTransformSaver::SaveTransform()
{
	AActor* Owner = GetOwner();
	if(Owner != nullptr)
	{
		//this->TRS = Owner->GetActorTransform();
		Cast<UTransformSaver>(GetClass()->GetDefaultObject())->TRS = Owner->GetTransform();
	}else
	{
		UOrama_Util::PrintMessage("Null Owner");
	}
}

The line i posted in my original post was in the SaveTransform() function which is a button (Call in Editor porperty).

So, as you said, i think that i DO change the value in cpp (check the savetransform() function).
(sorry for the commenting here but i couldnt comment at your question)

The .h file:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "TransformSaver.generated.h"


UCLASS(ClassGroup=(oramaVR), meta=(BlueprintSpawnableComponent) )
class SAMPLEAPP_API UTransformSaver : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UTransformSaver();
	UPROPERTY(EditAnywhere,Category="OramaVR")
	FTransform TRS;
	UFUNCTION(CallInEditor,Category="OramaVR")
	void SaveTransform();
protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

		
};

the .cpp file

// Fill out your copyright notice in the Description page of Project Settings.


#include "TransformSaver.h"

#include "ComponentUtils.h"
#include "ConstructorHelpers.h"
#include "KismetEditorUtilities.h"
#include "Util/Orama_Util.h"

// Sets default values for this component's properties
UTransformSaver::UTransformSaver()
{
	PrimaryComponentTick.bCanEverTick = false;
	
}


void UTransformSaver::SaveTransform()
{
	AActor* Owner = GetOwner();
	if(Owner != nullptr)
	{
		//this->TRS = Owner->GetActorTransform();
		Cast<UTransformSaver>(GetClass()->GetDefaultObject())->TRS = Owner->GetTransform();
	}else
	{
		UOrama_Util::PrintMessage("Null Owner");
	}
}

void UTransformSaver::BeginPlay()
{
	Super::BeginPlay();
	
}


void UTransformSaver::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// ...
}