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"

Setting default mesh to a class property

I want to create a tile-based map of a given size (like 8*8 tiles) from a given Tile (square or hexagonal). I plan to store this default mesh in a class property: UPROPERTY(EditDefaultOnly, Category = "Default Mesh") UStaticMesh * TileMesh; But the problem is that a don't know how to properly initialize this property (in c++ class) from an exist mesh in my project. I've tried CreateDeafaultSubobject(), static ConstructorHelpers::FObjectFinder MyMesh(TEXT(%mesh reference%)), but it is always NULL on game start. How can i set default mesh to my class property?

Product Version: Not Selected
more ▼

asked Apr 16 '15 at 08:04 AM in C++ Programming

avatar image

23 2 3 6

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

1 answer: sort voted first

If you want to use your method of exposing it as a class property, like so :

 UPROPERTY(EditDefaultsOnly, Category = "Default Mesh") 
 UStaticMesh* TileMesh;

Than, you need to create a Blueprint in the editor with your class. In this blueprint, in the Class Defaults section, you will have your property show up there so you can select a Static Mesh from those you have imported in your game.

Otherwise, you can use the object finder to automatically load the mesh in your class constructor like so :

 ATestActor::ATestActor(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
     PrimaryActorTick.bCanEverTick = true;
     static ConstructorHelpers::FObjectFinder<UStaticMesh> MyMesh(TEXT("StaticMesh'/Game/ThirdPerson/Meshes/CubeMesh.CubeMesh'"));
     TileMesh = MyMesh.Object;

Of course this is only the static mesh, to actually use it you need to assign it to a StaticMeshComponent, but I guess you already know that?

Hope this helps!


more ▼

answered Apr 16 '15 at 11:28 AM

avatar image

2.1k 70 38 259

avatar image Ars_Siegfried Apr 16 '15 at 12:25 PM

Damn it! i knew it was really simple, but still i didn't get it. Thank you! This line i was looking for - TileMesh = MyMesh.Object; I was tryint to use Get,Assign,Attach etc.

I'm not sure if i fully understand mesh component system: i thought that when you spawn an Actor you aasign mesh to it (like StaticMesh) and then if you need additional parts - you create StaticMeshComponent and attach it to basic mesh.

About Blueprint - i made it blueprint accessible to be sure it works :) but i needed it through c++

avatar image MickD777 Apr 17 '15 at 12:46 AM

Great, you can tag it as an accepted answer than :)

(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