x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to get inherited Mesh Component to show in BP editor?

I'm sure this'll end up with a simple answer, but I cannot for the life of me figure it out. In the base C++ class of which the Blueprint is based on, I have a Scene Component as its root and a Static Mesh Component for visual representation. All this is being done in the constructor.

AFoodBase::AFoodBase()
{
    PrimaryActorTick.bCanEverTick = false;
    USceneComponent* SC = CreateDefaultSubobject
  
   (TEXT("Root Component"));
    RootComponent = SC;
    UStaticMeshComponent* Mesh = CreateDefaultSubobject
   
    (TEXT("Mesh"));
    Mesh->SetStaticMesh(ObjectMesh);
    Mesh->SetRelativeLocation(FVector(0.f, 0.f, -5.f));
}
   
  
(because the tags are breaking, see picture for complete code) alt text

The mesh I want to use in for the visual representation is set in the editor through the variable ObjectMesh declared in the class' header. However, the mesh set in the editor doesn't show up in the blueprint editor. Which while survivable, is just a pain to work with.

alt text

Now, to get around this I could just hard-code the mesh's location into the code, specifically the constructor, but I don't want to do that for obvious reasons. To get to show the mesh during gameplay, I'd need to move Mesh->SetStaticMesh(ObjectMesh); into the BeginPlay() function. However, what I don't know how to do is get the mesh to show up in the BD editor window.

Any help figuring out how to show it in said window would be much appreciated.

Cheers

Piccadi11y

Product Version: UE 4.21
Tags:
ue4query.png (993.4 kB)
ue4query2.png (13.8 kB)
more ▼

asked Nov 16 '18 at 03:58 AM in C++ Programming

avatar image

Piccadi11y
5 1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

While redbox's answer did result in results very similar to what I needed, it wasn't quite there. After rethinking the problem, the way I'm going about implementing the class' functionality doesn't allow for the visual feedback I was after. For this reason I'm going to mark this question as answered and hope that someone who finds there way here can either get the help they need from it (it's very valid code) or come to the same conclusion as me.

more ▼

answered Nov 16 '18 at 09:19 AM

avatar image

Piccadi11y
5 1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

You should declare mesh component as, for example, UPROPERTY(VisibleAnywhere, EditDefaultsOnly). With it you can set mesh directly into this component in editor.

more ▼

answered Nov 16 '18 at 05:21 AM

avatar image

redbox
4.2k 80 17 103

avatar image Piccadi11y Nov 16 '18 at 05:32 AM

As you can see in the top right of the second screenshot (of the bp editor), I do have the capacity to set a mesh to be used. This is done in the header file with the UPROPERTY(EditAnywhere, Category = Fruit Variables) macro. As you can also see, I have selected a mesh of mine to be used. The problem is the UStaticMeshComponent (on the left, child to the USceneComponent[root]) isn't being updated in editor to visually reflect this. I.e. the mesh doesn't appear in the viewport. Will adding either of your suggestions to the UPROPERTY() macro allow this to happen, or is another solution needed?

avatar image redbox Nov 16 '18 at 06:19 AM

I don't understand why you want to set static mesh using some additional variable, if you can select staticmeshcomponent in editor and set it from there.

Anyway, if you want to do this through variable in Editor - you must make it in ConstructionScript or use PostEditChangeProperty() function.

avatar image redbox Nov 16 '18 at 07:40 AM

Here is an example:

header:

     //Override PostEditChangeProperty
 #if WITH_EDITOR
     virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
 #endif

cpp:

 //Update with changed property
 #if WITH_EDITOR
 void AFoodBase::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
 {
     Super::PostEditChangeProperty(PropertyChangedEvent);
     FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None;
     if (PropertyName == TEXT("ObjectMesh"))
     {
         Mesh->SetStaticMesh(ObjectMesh);
     }
 }
 #endif

avatar image Piccadi11y Nov 16 '18 at 09:20 AM

Cheers redbox for your help. Like I said in the post I've marked as answered, the help you've given me answered the question I was asking, just not the question I thought I was trying to ask. Thanks again for your time.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question