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 expose a UStaticMeshComponent to be assigned in Blueprints

I have written an actor class in C++.

I have a blueprint that inherits from this actor class and contains multiple static meshes.

I would like to reference a particular one of these static meshes from within blueprints.

I tried doing this by adding the following to the actor's header file

 UPROPERTY(EditAnywhere)
 UStaticMeshComponent* SurfaceMesh = nullptr;

but this did not cause anything to show up in the editor.

Is there any way to do this? If not, what is my best alternative?

Product Version: UE 4.18
Tags:
more ▼

asked Dec 19 '17 at 02:51 PM in C++ Programming

avatar image

jonnybolton42
12 3 4 7

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

4 answers: sort voted first

Hey there, try:

 UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Test")

And don't forget to initialize it on the constructor:

Mesh = ObjectInitializer.CreateDefaultSubobject(this, TEXT("Mesh"));

more ▼

answered Dec 19 '17 at 03:37 PM

avatar image

xlar8or
6k 161 129 304

avatar image jonnybolton42 Dec 19 '17 at 04:17 PM

Hi thanks for the reply. I am not trying to initialize a new mesh, I have a preexisting mesh within the blueprint that I want to have access to in code.

I have worked around the problem by calling GetComponentsByClass and then looping through the results to find the one I require, but this seems inefficient. I would much prefer if the reference was serialized out to the editor.

avatar image xlar8or Dec 19 '17 at 05:49 PM

And how do you create the mesh? using NewObject? If you create it somewhere you can also store the reference to it in code.

avatar image jonnybolton42 Dec 19 '17 at 05:52 PM

It is not being created at runtime. The blueprint class contains the mesh as a component.

avatar image xlar8or Dec 19 '17 at 05:54 PM

So if you add the static mesh in blueprints and you're trying to access it by c++ then the only way to get that is to go through all of the static mesh components using GetComponentsByClass and checking the name. The thing is you can do that in BeginPlay and it will only happen once, so it's fine.

avatar image jonnybolton42 Dec 19 '17 at 05:57 PM

Ok, I'll keep doing it that way. That's working for me. Thanks for your help.

avatar image xlar8or Dec 19 '17 at 06:00 PM

Eventually you could use GetcomponentByTag and you would just tag the component you want, but that should iterate through them, so it should be same thing.

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

try this.

 class UStaticMeshComponent* SurfaceMesh;
more ▼

answered Dec 19 '17 at 03:16 PM

avatar image

JoSilver
236 8 13 22

avatar image jonnybolton42 Dec 19 '17 at 03:21 PM

No luck with that either.

avatar image JoSilver Dec 19 '17 at 03:24 PM
 UPROPERTY(EditAnywhere, BlueprintReadWrite)
     class UStaticMeshComponent* SurfaceMesh;
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Try to add

 UPROPERTY(EditAnywhere, BlueprintReadWrite)

more ▼

answered Dec 19 '17 at 02:56 PM

avatar image

shh---
104 1 3 9

avatar image jonnybolton42 Dec 19 '17 at 02:58 PM

That doesn't work either unfortunately

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

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BodyPart")

UStaticMesh* BodyPart;

more ▼

answered Feb 03 '19 at 04:58 PM

avatar image

SWS-7
1 2

(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