Why can't I edit my USkeletalMeshComponent?

Hello,

I am trying to write a simple item class that has a string and a skeletalmesh attached to it. Here is my Code:

Item.h:

#pragma once

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

/**
 * 
 */
UCLASS()
class AItem : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = General)
	FString ItemName;

	UPROPERTY(BlueprintReadOnly, Category = General)
	TSubobjectPtr<USkeletalMeshComponent> SkeletalMeshComponent;
	
};

Item.cpp:

#include "Noreia.h"
#include "Item.h"


AItem::AItem(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	//create new object
	TSubobjectPtr<USphereComponent> CollisionComp = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("CollisionComp"));
	CollisionComp->InitSphereRadius(100.0f);
	RootComponent= CollisionComp;

	SkeletalMeshComponent = PCIP.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("SkeletalMesh"));
	SkeletalMeshComponent->AttachParent = CollisionComp;

}

It compiles, but i cannot edit the Mesh in the editor. Also there is a DefaulSceneRoot in the Vlueprint Components View:

What am I missing here?

Because you can’t edit C++ made components in blueprint editor, i as trying way to edit them myself but i didn’t find the way either.

Considering you making a base class for item, i recommend you to not define components there, instead make base class with functions you need for item to behave as you like (together with useful blueprint node to support your item behavior) and make items in blueprint together with components based of that class :slight_smile: If you need extra C++ for some item you can make another base class out of item class. You can interact with blueprint made components via C++ in base class via variables in AActor class (like RootComponent or GetComponents()).

1 Like

I know for a fact, that you actually can edit components, at least in the Defaults Window of the Blueprint. I allready got it working once and ma pretty sure that I didn’t do much different stuff then I am trying now. Too bad I dont have the old Sourcecode anymore.

So just to clarify: I just want to be able to set the Sekeletal Mesh of my Skeleteal Mesh Component in the Defaults Window.

I believe you you need to set your component to be visible using VisibleAnywhere and then create a blueprint out of the C++ class.

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = General) TSubobjectPtr SkeletalMeshComponent;

I just ran into this. My UProperty looked like this:

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly category = Floater)
	TSubobjectPtr<class USkeletalMeshComponent> Mesh;

Which caused your issue. But when I removed the “BlueprintReadOnly” bit, it worked. Correct code looks like this:

	UPROPERTY(VisibleAnywhere, category = Floater)
	TSubobjectPtr<class USkeletalMeshComponent> Mesh;

Yes this is the correct way to do it, though you may change some access modifiers in general

please accept the correct answer it i’ll help people find answers faster

I, too, ran into this issue and now TSubobjectPtr is marked as Deprecated (currently only a warning).

UPROPERTY( VisibleAnywhere, Category = "Some|Category", meta = ( AllowPrivateAccess = "true" ) )
		USkeletalMeshComponent*					MyMesh;

The above is what I have used and it’s working fine when viewing/editing a Skeletal Mesh, in the Editor, with the default property view.
(I use “|” pipe separators between categories to provide sub-catogories, in case anyone was wondering what is the character between Some and Category)

Now (2021) TSubobjectPtr it’s definitely deprecated and it gives you errors in the console, so you can’t use it. The solution with Unreal 4.27 was to set the UPROPERTY VisibleDefaultsOnly(or higher) and BueprintReadOnly(or higher), in my case I used BlueprintReadWrite because I need to interact with the component in blueprints.

UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite, Category="Door Component")
class USkeletalMeshComponent *DoorRunic;

You NEED to delete the blueprint and recreate it from the C++ class if you previously created with the wrong properties because it doesn’t refresh!
I wasted so much time on this and I hope I could help someone else!

1 Like

I advice instead of pervious code, you must write something like this

In .h file :

#pragma once
#include "GameFramework/Actor.h" 
#include "Item.generated.h" 

/** * */ 

UCLASS() 
class AItem : public AActor
 { 
GENERATED_UCLASS_BODY()

 UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = General)
 FString ItemName; 

UPROPERTY(VisibleAnywhere , BlueprintReadOnly , Category = "general" )
class USkeletalMeshComponent * SkeletalMeshComponent; 

 };  

In .cpp file :

#include "Noreia.h"
#include "Item.h"
#include "Components/SkeletalMeshComponent.h"
 
AItem::AItem()
{
 SkeletalMeshComponent= CreateDefaultSubobject<USkeletalMeshComponent>(" skeletal mesh ");
}

After that you must delete your bp and make it again , because after making the bp some changes in c++ may not effect on inherited bp

In this way your problem should solve , I had that problem too, if you get the true result please mark the comment as the answer to help others those who have problem

2 Likes

You don’t need to recreate it, reparent to someting else and back to modified parent class in the Class Settings in Blueprint is enough

As far as I Remember I tried reparenting before deleting it and I had no luck, the engine sometimes has inconsistent behaviours and I wasn’t able to identify what they depend on. By the way I’ve recently discovered a free plugin to transfer properties between blueprints instead of creating them manually, I think it’s really useful!

1 Like