UStaticMeshComponent doesn't show Details Panel

Hi I’m working on a game where I have several different shields that I can use for certain characters. So I CreateDefaultSubobject and attach it to the Rootcomponent. This works all well and inside the game I get my shield however in my Blueprint I get not details panel for it.

What I’m doing is reading a DataAsset in Character constructor and getting the shield that a certain character has and with an if else statement decide which one to create.

If I don’t have the if else statement and only one specific Component I can see the Details Panel and play around with it. But with the if else statement if just doesn’t show up. I do see a that the Component is Inherited.

Does anyone know why this might occur or if anyone might know a fix to the problem?

Currently Working on a Macbook Pro OSX, UE 4.8.3

Are you using this?

UPROPERTY(Category = MeshComp, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))

If yes , can you post the code where the component is created , this will help to have a clear idea

I might have posted a reply but I don’t see it in here so I’ll do a post again.

Since I’m not at home atm, this is the basic structure of the code.

.h
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = MyComponent, meta = (AllowPrivateAccess = "true"))
class UMyComponent_Shield* ShieldComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = MyComponent, meta = (AllowPrivateAccess = "true"))
class UMyComponent_Deflect* DeflectComponent;


.cpp
AMyRobotCharacter::AMyRobotCharacter()
{
	FString GetComponentName = GetDataAsset_Things_WithStaticLoadObject.TSubclassOf < UMyComponent >;

	// Set Movement
	// Set Camera
	// etc

	if (GetComponentName.Contains(TEXT("Shield"))
	{
		ShieldComponent = CreateDefaultSubobject<UMyComponent_Shield>(TEXT("Shield Component"));
		ShieldComponent->AttachTo(RootComponent);
	}
	else if (GetComponentName.Contains(TEXT("Deflect"))
	{
		DeflectComponent = CreateDefaultSubobject<UMyComponent_Deflect>(TEXT("Deflect Component"));
		DeflectComponent->AttachTo(RootComponent);
	}
}

If you only use one of either Shield or Deflect component it works and you can see the Details Panel. But if you do this if else statement it doesn’t display the contents. If I put both of them in the editor crashes so I can’t have 2 UStaticMeshComponent and then remove one from the game after Initialization.

Currently I have Data Assets for my Characters setup & stats, so I set in there what component I want my specific Character to use, since I want to have different Robots with different abilities.

I hope this gives a better idea.

Instead of having two UStaticMeshComponents that you’re swapping out I’d suggest using a single UStaticMeshComponents and two UStaticMesh variables that you switch between. Something like this:

.h
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = MyComponent, meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* HoldingComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = MyComponent, meta = (AllowPrivateAccess = "true"))
class UStaticMesh* ShieldMesh;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = MyComponent, meta = (AllowPrivateAccess = "true"))
class UStaticMesh* DeflectMesh;

.cpp
AMyRobotCharacter::AMyRobotCharacter()
 {
     FString GetComponentName = GetDataAsset_Things_WithStaticLoadObject.TSubclassOf < UMyComponent >;
 
     // Set Movement
     // Set Camera
     // etc

     HoldingComponent = NewObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass());
     HoldingComponent->AttachTo(RootComponent);
     if (GetComponentName.Contains(TEXT("Shield"))
     {
         HoldingComponent->SetStaticMesh(ShieldMesh);
     }
     else if (GetComponentName.Contains(TEXT("Deflect"))
     {
         HoldingComponent->SetStaticMesh(DeflectMesh);
     }
 }

Yea that’s not a bad idea. Never though of it like that. I’ll give it a try. Thank you mfish.