UCLASS()
class MIKETEST_API AMyTriggerBox : public AActor
{
GENERATED_BODY()
public:
AMyTriggerBox(const FObjectInitializer& ObjectInitializer);
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
private:
class UBoxComponent* _box;
UPROPERTY(EditDefaultsOnly)
class UStaticMeshComponent* MeshComp;
};
Cpp File
#include "MyTriggerBox.h"
#include "Components/BoxComponent.h"
#include "Engine.h"
AMyTriggerBox::AMyTriggerBox(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
_box = CreateDefaultSubobject<UBoxComponent>(TEXT("Box"));
_box->SetHiddenInGame(false);
_box->OnComponentBeginOverlap.AddDynamic(this, &AMyTriggerBox::OnBoxOverlapBegin);
_box->OnComponentEndOverlap.AddDynamic(this, &AMyTriggerBox::OnBoxOverlapEnd);
RootComponent = _box;
UStaticMeshComponent* MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("TheMesh"));
}
So what have you tried. You’ve tried changing it to protected/public. Where are you trying to change the information. I’m going to load your code into my own project and see what’s going on.
I think you should re-read the answer I linked above. What are you trying to edit about the component? If you’d like to change the mesh, you do that in the TriggerBox as there is a property called Mesh Comp (See image)
I’m bit confused by some of your code and it could be what’s causing the issue. I notice that you declare your UProperty in your .h here:
UPROPERTY(EditDefaultsOnly)
class UStaticMeshComponent* MeshComp;
But when you go to use CreateDefaultSubobject to populate it, you aren’t setting it, you’re declaring yet another UStaticMeshComponent called MeshComp as well,
If you remove the “UStaticMeshComponent*” from the start of this line, it may fix your problems. The compiler is likely ignoring the original one that was declared in the .h and showing you this one, which is not a UProperty.
You still have the UPROPERTY set to Private and are also not using BlueprintReadWrite or a Category, which could help, depending on where you’re looking. With the screenshot you’re providing, I cannot tell which Details panel this is. Also, a Static Mesh Component would show up in the Components list, not in the same place as a normal Static Mesh or a Float value.
Can you show the constructor? If it is only containing RootComponent = MeshComp;, that’s also an issue as your UStaticMeshComponent needs to be initiated, using CreateDefaultSubobject, it just needs to be done correctly.
UPROPERTY(EditDefaultsOnly,Category “My Mesh”)
class UStaticMeshComponent* MeshComp;
Just for my education.
Why are you using “class” with an object declaration within the .h ?
Try without it and maybe the editor will catch your mesh.
Using “class” allows for him to forward declare a class that has not been included in the .h file. This allows him to declare the property in his .h, and only include the necessary file in his .cpp.
However, I agree. This shouldn’t be needed for UStaticMeshComponent at least as it shouldn’t need to be forward declared unlike UBoxComponent would.
UProperty is set to private even for the float variable and for the StaticMesh. So I don’t see the reason why it shouldn’t work for the MeshComponent.
Also, each of them has a category assigned.
As you can see there IS the MeshComponent on the left, but in an older project from Unreal Engine 4.13, I have the StaticMeshComponent behaving like the current StaticMesh: a box where I could choose the 3D Model to apply.
For the “it just needs to be done correctly”.
Well… there is a HUGE leak of documentation about using Unreal Engine with C++.
Yes, there are the basics… but many times it’s HARD to even find the documentation of an UE API class.
Not to talk about the Multiplayer… let’s just pretend I didn’t talk about it…
Thank you for the screenshot. I see why you aren’t able to edit it now. You are looking at this inside of a blueprint. If you wish for this UStaticMeshComponent to be accessible in Blueprints, you’ll need to use the BlueprintReadWrite, or BlueprintReadOnly if you only want to see it, specifier in your UProperty declaration as well. It is also not always safe to assume that a Component is going to work the same way as a variable, as they are vastly different. There is not a gap of documentation in this respect, as there are resources that explain this such as this tutorial: https://docs.unrealengine.com/latest/INT/Videos/PLZlv_N0_O1gYup-gvJtMsgJqnEB_dGiM4/
Another thing to keep in mind is that UE4 is an ever changing engine. I understand that the lay out may have been different in 4.13 but there have been many changes since then. If you do wish for the editor to stay the same, there is nothing wrong with staying on an older version of the editor for development, as upgrading to a newer version will often pose problems for existing projects.