Hey all,
I’m a newbie to Unreal and c++ with only 1.5 weeks of learning experience and have a question about workflow:
Given AActor:
#ExampleActor.h
UCLASS()
class EXAMPLE_API AExampleActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AExampleActor();
UPROPERTY(VisibleAnywhere)
class UExampleComponent* ExampleComponent;
};
...
#ExampleActor.cpp
#include "ExampleComponent.h"
AExampleActor::AExampleActor()
{
USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent"));
RootComponent = SphereComponent;
ExampleComponent = CreateDefaultSubobject<UExampleComponent>(TEXT("ExampleComponent"));
AddOwnedComponent(ExampleComponent);
}
And UMovementComponent:
#ExampleComponent.h
UCLASS()
class EXAMPLE_API UExampleComponent : public UMovementComponent
{
GENERATED_BODY()
public:
UExampleComponent();
UPROPERTY(EditAnywhere)
float MoveSpeed;
};
...
#ExampleComponent.cpp
UExampleComponent::UExampleComponent()
{
}
Now, when I place ExampleActor somewhere in the level (it becomes ExampleActor1), I can easily modify it’s ExampleComponent’s MoveSpeed. This is an amazing feature of the editor that like very much
Sadly, if I, for example, add or remove a UPROPERTY, eg.:
#ExampleComponent.h
UCLASS()
class EXAMPLE_API UExampleComponent : public UMovementComponent
{
GENERATED_BODY()
public:
UExampleComponent();
UPROPERTY(EditAnywhere)
float MoveSpeed;
UPROPERTY(EditAnywhere)
float BrakingForce;
};
And then compile:
Expected behavior:
Actor instance keeps it’s ExampleComponent editable.
Actual behavior:
ExampleActor1’s ExampleComponent becomes uneditable with a message: native components are editable when declared as a property in c++.
Placing a new actor in the level instantiates an actor (ExampleActor2) with an editable ExampleComponent, while ExampleActor1 remains with un-editable one. Interestingly, after compilation, ExampleActor1’s ExampleComponent reflects changes - the new UPROPERTY is visible.
What I tried:
- Changing UPROPERTY - EditAnywhere, VisibleAnywhere.
- Adding, removing UPROPERTY.
- Restart Unreal Engine.
- Restart computer.
- New project with bare minimum code.
So my assumption was that such workflow (Add components to an AActor in its construction script, add the AActor to level, edit component properties in editor, change component code and compile, change component properties on the same actor in editor) was the way to go.
Seems like if I have 100 actors in a level and change one of their component’s code, having to remake all 100 actors would be a pain.
So basically my question is:
Is this a bug, or to achieve the intended results of my newbie workflow I need to do something else?
Thank you