Download

Making attached component editable

Hi guys

I have a component that I’m attaching to actors in a map. Right now it seems to be locked down, despite declaring everything I want to edit as UPROPERTY():

The member is set to public and used like this:


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Lighting") ERenderResolution RenderResolution = ERenderResolution::RR_AUTO;

So I think the problem isn’t the member above, it’s actually the way I’m attaching the new component to the actor:


OctaneComponent = NewObject<UOctaneComponent>(Actor);
OctaneComponent->RegisterComponent();

OctaneComponent->SetFlags(RF_MarkAsNative);

Is there anything else I need to do to this to get it to be editable?

OctaneComponent->bEditableWhenInherited = true; or something of that sort.

Gotcha, thanks!

That didn’t do it I’m afraid. There don’t seem to be any other properties relevant to making it editable either.

Scratch that, I had to click the parent to see and edit the property. Thanks again! :slight_smile:

Edit: and as quickly as it was there, it’s gone again. I’m so confused. I can even see the modified value in the component but I can’t find the enabled dropdown again in any other objects.

where are you calling this code (in a function, constructor, etc)?

I’m setting this in the constructor:


	SetFlags(RF_MarkAsNative | RF_Dynamic | RF_Standalone);
	MarkAsEditorOnlySubobject();

	bEditableWhenInherited = true;
	bWantsBeginPlay = false;
	PrimaryComponentTick.bCanEverTick = true;

And this after spawning a new object:


OctaneComponent = NewObject<UOctaneComponent>(Actor);
OctaneComponent->RegisterComponent();

I’ve been moving things around and trying different things so those flags are random guesses.

I believe you set that bool right after you attach the component to the actor. Right?

In my code i set it after I set my attach pointer.

Of course, I am setting it to false to deny access to the component properties. So I think you should be able to edit the component by default.


ObjectSocketSprite->AttachTo(VisualMesh, "StopSignSocket");        
ObjectSocketSprite->bSelectable = false;
ObjectSocketSprite->bEditableWhenInherited = false;

hm in the actor your attaching it to have your tried declaring it in it’s header im pretty sure you have idk im not good at this

ex:



UPROPERTY(BlueprintReadWrite, VisibleDefaultsOnly, Category = )
class UOctaneComponent* OctaneComponent;


pls note im still terrible at programming and all code is as is >_<

Not possible as I have no control over what kind of actor the component is attached to.

I had this working when adding the properties to an actor directly which was cool, but it seems more complicated to try to get the actor to display properties for a component.

Hmm good idea, I’ll try that. I’m not doing an attach, just providing the actor as an Outer. It’s not a scene component so doesn’t need anything other than to have that actor as the owner (I think!)

Moving things back out to beyond when the component is registered also didn’t seem to make a difference. Bit of a mind****, I wish I knew how it managed to work for a few seconds.

Maybe I don’t get the specific but is there a reason why you go for newObject() instead of CreateDefaultSubObject () ?

I thought newObject () is rather if your owner is not an actor…

I didn’t know that. What constitutes a default subobject though? Most of these actors are actually static mesh actors with a static mesh. I don’t think I want to replace the static mesh behaviour with something else - I’m just adding an extra component that provides additional editor functionality to that actor.

Try this instead of NewObject:
OctaneComponent = CreateDefaultSubobject<UOctaneComponent>(TEXT(“Descriptive Text Goes Here”));

I believe in the following code you are creating a new Actor Object? I am not very skilled with c++ either but if this component is a child of the main actor class and only used to add additional functionality that it should be a SubObject. Again, I do not know if I am near correct in my assumptions.



OctaneComponent = NewObject<UOctaneComponent>(Actor);
OctaneComponent->RegisterComponent();

Also, this way I think if you call it in the constructor it is auto registered, the only time you would call RegisterComponent(); is if you are making property changes, etc… I think.

Oh right, CreateDefaultSubobject needs to be called in the constructor.

So my setup is:

  1. User downloads UE plugin
  2. Opens existing scene
  3. Plugin walks existing scene attaching my component to actors of various kinds
  4. My component does stuff

So there’s no opportunity to do that, even if I wanted to replace their static mesh component as the default subobject and break their static mesh actor’s transforms.

I’m not fussed about where the property I’m trying to edit is, just that it’s editable. It’s OK for it to be on the component rather than the actor. I’m just confused as to what else it needs to be a “native component” like the restriction tooltip says.

I looked into the code that generates that tooltip a while ago, and it seemed pretty arbitrary to me. Like it was an imposed limitation that shouldn’t really be necessary. Anyway, from what I remember, it means that in practice you can’t edit component properties for dynamically added components (those created with NewObject as opposed to CreateDefaultSubobject). As you say, for your situation, you have no choice about that.

As for what causes component properties to sometimes show up directly on the details panel of the parent actor, I’ve never worked that out.

Fun. Thanks for the reply, I guess I’ll make a new inspector.

Wait, that sounds like too much work. I think I’ll just make a new StaticMeshActor class and replace whatever I find with it, transferring over all the properties. Does that sound reasonable?

My first hurdle is that there’s a LOT of data in a static mesh actor to copy over, not just the static mesh itself. I need to maintain render settings, collision settings, all of that sort of thing. Is there a way to create a new object based on another object? My new AMyStaticMeshActor class inherits directly from AStaticMeshActor - what’s the best way to either change or copy an object that already exists?