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"

Dynamicly spawn TileMaps

I'm trying to dynamicly spawn tilemaps as my levels are generated procedurally. Each tilemap is a room, made in the editor, and could be spawned multiple times.

My approach right now is to create a single actor, and adding Tile map components for each room. This works fine if the generation is done within the constructor, however I need it to be dynamic, so following https://answers.unrealengine.com/questions/199144/add-components-dynamically.html I tried the following code :

 void AMapGenerator::BeginPlay()
     UPaperTileMapComponent* createdComp = NewObject<UPaperTileMapComponent>();
     if (createdComp)
         createdComp->AttachTo(GetRootComponent(), NAME_None);

The new component isn't registered upon creation, but RegisterComponent() will give a crash :

 Ensure condition failed: MyOwner && MyOwner->GetWorld()

I also thought of using a single huge tilemap and copy parts of my rooms, but I'm not sure that it would be efficient.

What would be the best approach in this case ?

Product Version: UE 4.10
more ▼

asked Nov 22 '15 at 04:41 PM in C++ Programming

avatar image

13 2 4 6

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

1 answer: sort voted first

Try passing a value to the Outer parameter of the NewObject function. That will set the owner property of the component so registration can succeed.

 UPaperTileMapComponent* createdComp = NewObject<UPaperTileMapComponent>(this);
more ▼

answered Nov 22 '15 at 05:55 PM

avatar image

866 36 14 59

(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