Download

Actor's components un-editable in editor after compilation of said components

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 :slight_smile:
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 :slight_smile:

It’s definitely a bug and not expected behaviour. I’ve seen similar bugs before, but usually resulting from switching component class, not from merely adding or removing a property.

Phew, that’s reassuring, I was afraid that I fundamentally misunderstood how to work with the Engine.
Also a bit of an update: restarting the Engine sometimes works, but it’s not deterministic. Still, at least it is manageable now. Sadly, I lack the skill to even begin debugging, so I cannot be of any help :frowning:

Try UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly) or UPROPERTY(EditAnywhere, BlueprintReadWrite)
You can also try adding UCLASS(BlueprintType)

Thank you, I will try them. Though I have to ask - will BlueprintReadOnly, BlueprintReadWrite, BlueprintType change anything if I don’t use blueprints at all? Are they somehow used to connect c++ code and the editor itself? I would love to know these things :slight_smile:

Yep, it is a bug !
For me it worked if I removed the component from the code,
compiled,
then add it again to the code.