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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Container data disappears


I'm trying to create a data structure where actors contain others actors by referencing them in containers as TMap or TArray. To explain a bit, I created a AWall class, a ALabyrinthCell class which reference AWall objects in a TMap and ALabyrinthBody which have a two dimensionnal TArray referencing ALaryrinthCell objects.

I have no problems to spawn these actors as i want to, but once I try to access let's say ALabyrinthCell container through the ALabyrinthBody container, all the data is gone. Anyone has an idea of what i am doing wrong ?



 #pragma once
 #include "Wall.h"
 #include "GameFramework/Actor.h"
 #include "LabyrinthCell.generated.h"
 class LABYRINTH_API ALabyrinthCell : public AActor
     // Sets default values for this actor's properties
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
     // Called every frame
     virtual void Tick( float DeltaSeconds ) override;
     void formCell();
     void abattreMur(FString cote);
     TMap<FString, class AWall*> getCell() const { return cell; }
     TMap<FString, class AWall*> cell;


function which fills the container

 void ALabyrinthCell::formCell()
     if (GetWorld() != nullptr)
         FVector *v = new FVector(GetTransform().GetLocation().X, GetTransform().GetLocation().Y, GetTransform().GetLocation().Z);
         FRotator *r = new FRotator(0.f, 90.f, 0.f);
         cell.FindOrAdd("north") = (AWall*) GetWorld()->SpawnActor(AWall::StaticClass(),v,r);
         cell.FindOrAdd("east") = (AWall*)GetWorld()->SpawnActor(AWall::StaticClass(), v);
         cell.FindOrAdd("west") = (AWall*)GetWorld()->SpawnActor(AWall::StaticClass(), v);
         cell.FindOrAdd("south") = (AWall*)GetWorld()->SpawnActor(AWall::StaticClass(), v,r);
         FVector Orgin;
         FVector size;
         cell["north"]->GetActorBounds(false, Orgin, size);
         v->Set(GetActorLocation().X, GetActorLocation().Y - size.X, GetActorLocation().Z);
         v->Set(GetActorLocation().X, GetActorLocation().Y + size.X, GetActorLocation().Z);
         v->Set(GetActorLocation().X + size.X, GetActorLocation().Y, GetActorLocation().Z);
         v->Set(GetActorLocation().X - size.X, GetActorLocation().Y, GetActorLocation().Z);

ALabyrinthBody container is a TArray >

ALabyrinthBody function which fills it

 void ALabyrinthBody::formGrid(int x, int y)
     AWall* w = GetWorld()->SpawnActor<AWall>();
     FVector Orgin;
     FVector size;
     w->GetActorBounds(false, Orgin, size);
     FVector *position;
     FVector *origin;
     //Test si on a un nombre pair ou non de ligne et de colonne dans la grille 
     if (y % 2 == 0) {
         if (x % 2 == 0)
             position = new FVector((GetTransform().GetLocation().X - size.Y) - (x*size.Y), (GetTransform().GetLocation().Y - size.Y) - (y*size.Y), GetTransform().GetLocation().Z);
             position = new FVector(GetTransform().GetLocation().X - (x*size.Y), (GetTransform().GetLocation().Y - size.Y) - (y*size.Y), GetTransform().GetLocation().Z);
     else {
         if (x % 2 == 0)
             position = new FVector((GetTransform().GetLocation().X - size.Y) - (x*size.Y), GetTransform().GetLocation().Y  - (y*size.Y), GetTransform().GetLocation().Z);
             position = new FVector(GetTransform().GetLocation().X - (x*size.Y), GetTransform().GetLocation().Y - (y*size.Y), GetTransform().GetLocation().Z);
     origin = new FVector(*position);
     for (int i = 0; i < y; i++)
         for (int j = 0; j < x; j++)
             body[i].Add((ALabyrinthCell*) GetWorld()->SpawnActor(ALabyrinthCell::StaticClass(), position));
             position->Set(position->X, position->Y + size.Y*2, position->Z);
         position->Set(position->X + size.Y*2, origin->Y, position->Z);
         GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, FString::FromInt(body[0][0]->getCell().Num()));

Here's the visual result when I send (2,2) to formGrid alt text

And when i try something like "body[0][0]->getCell()" the TMap is empty, why ?

Product Version: UE 4.10
labyrinthbody.jpg (67.0 kB)
more ▼

asked May 04 '16 at 10:32 AM in C++ Programming

avatar image

6 2

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

1 answer: sort voted first

Resolved! For some reasons, I wasn't able to access to TMap data of ALabyrinthCell because i called the function which fills this container inside BeginPlay() of ALabyrinthCell

Calling this function right after spawning the ALabyrtinthCell from the ALabyrinthBody class did the trick.

more ▼

answered May 09 '16 at 11:53 AM

avatar image

6 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