Bug with default values for Location, Rotation and Scale

Hi all.

I can’t setup the default values for the transform tab. The code for the test actor’s class:

TestActor.h

#pragma once

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

UCLASS()
class TESTPROJECT_API ATestActor : public AActor
{
	GENERATED_BODY()

	UPROPERTY(VisibleDefaultsOnly, Category = "Components")
	class UStaticMeshComponent* mesh1;

	UPROPERTY(VisibleDefaultsOnly, Category = "Components")
	class UStaticMeshComponent* mesh2;

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

TestActor.cpp

#include "TestProject.h"
#include "TestActor.h"

// Sets default values
ATestActor::ATestActor()
{
	static ConstructorHelpers::FObjectFinder<UStaticMesh> invisibleSphereMeshValue(TEXT("StaticMesh'/Engine/EngineMeshes/Sphere.Sphere'"));

	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneRoot"));
	
	mesh1 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Sphere1"));
	if (mesh1)
	{
		mesh1->RelativeLocation = FVector(150, 0, 0);
		mesh1->SetStaticMesh(invisibleSphereMeshValue.Object);
		mesh1->AttachParent = RootComponent;
	}

	mesh2 = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Sphere2"));
	if (mesh2)
	{
		mesh2->SetRelativeLocation(FVector(-150, 0, 0));
		mesh2->SetStaticMesh(invisibleSphereMeshValue.Object);
		mesh2->AttachParent = RootComponent;
	}
}

As a result, positions of spheres is not default values, looks like them were moved by user in editor.
sphere1
sphere2

If I change relative position in code, then this will not affect on components that already in the editor.

I don’t quite understand your question, but I’ll take a stab at helping you.

So, you have TestActor. TestActor has two subcomponents, mesh1 and mesh2. Mesh1 and mesh2 have some default position.

Are you creating an instance of TestActor in code or placing it in the editor from a blueprinted version?

When you create TestActor, you expect mesh1 and mesh2 to be where? They’re subcomponents, so I believe they’ll be using coordinates in the object’s local space rather than world space. That is, the subcomponents will be wherever the actor is, but offset on either side by 150 units.

Also, a picture of where the meshes are compared to where you expect them to be might be helpful.

Hi mdeni,

If I understand your problem correctly, you’re concerned that when you change the location, rotation and scale in C++ code, actors already in the scene are not updated with the new defaults. Is this correct?

If so, I believe this is something that the folks at Epic have said is by design. I don’t recall the precise details, but this question came up in one of the training streams/videos they did a while back. I think their reasoning had to do with the difficulty of determining which values were still at the default values (and therefore should be updated). I think they gave an example where a user initially codes a default of (ex:) 100, changes the value for an actor instance (e.g. to 150), and then changes the default value in code to match. Is the instance now at default, or was it intentionally set to its value? Just as tricky, if the default value is changed again, should the instance change too or is it correct where it is?

I believe the workaround is to use the little yellow “reset to default” arrow to the left of the location, rotation, and scale values. It seems to only appear when the values are non-default and to restore them to the values specified in the C++ code when clicked.

Does this help?

Hi! Thank you for your answer. Yes you correctly understand my problem. Main issue is that if there are a lot of those actors in the scene. Hundreds or thousands. When I am changing the location of the component, am I need to click on the “yellow arrow” thousands times? Or there is another solution…

Hi! I am work only with C++ version of the actor, and I don’t use blueprints. The real location on the scene is not so important. Important thing is that the relative location of components is not default value. So, when I am changing this location in the C++ code, this doesn’t affect on actors already placed in the scene. Maybe I am doing something wrong?

I haven’t yet heard of a solution Epic recommends for this problem.

Personally, I might be inclined to add the actors dynamically once the level is loaded instead of placing them in the level manually. This would mean they’d always have the most recent defaults. It would also require some overhead, like keeping track of where you want the actors (e.g. a list of positions or transforms) and creating them when the level’s Begin Play event occurs.

Another possibility would be having your actor reapply the defaults when it is created (e.g. in its own Begin Play event). You could even be selective about it if you want. For example, keeping a list of old defaults and only reapplying the defaults to ones that are at an old default. That’s probably more complex than you need though.

Does this give you some ideas?

I think, I shall implement the second way. Strangely, that all other properties except these three have correct default values.

Hi mdeni,
I’m not sure if this is exactly what your looking for but I ended up needing to always set my actor to 0,0,0 in the editor when it was first created. I used the function:

virtual void PostActorCreated();

And circled the SetActorLocation with:
#if WITH_EDITOR

This allowed me to load the objects with modified positions after the designer made changes and saved the level.