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. 

How do I debug C++ code

Hi, I'm new to the Unreal Engine but I'm quite familiar with the C++ language.

I want to create a 3D game of life using a TMap of cubes. Here's the code of the Main Actor:

 // Fill out your copyright notice in the Description page of Project Settings.
 #include "GameOfLife.h"
 #include "MainDirector.h"
 // Sets default values
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     Size.X = 16;
     Size.Y = 16;
     Size.Z = 16;
     AnimationSpeed = 1.0f;
 // Called when the game starts or when spawned
 void AMainDirector::BeginPlay()
     int x, y, z;
     FVector origin = this->GetActorLocation();
     for (x = 0; x < Size.X; x++)
         for (y = 0; y < Size.Y; y++)
             for (z = 0; z < Size.Z; z++)
                 FVector index(x, y, z);
                 _cells[index] = false;
                 AActor* cell = GWorld->SpawnActor(Cell->GetActorClass());
                 if (cell)
                     FVector location = origin + CubeSize * FVector(x, y, z);
                     _spawnedActors[index] = cell;
 // Called every frame
 void AMainDirector::Tick( float DeltaTime )
     Super::Tick( DeltaTime );
     static float currentTime = 0.0f;
     currentTime += DeltaTime;
     if (currentTime >= AnimationSpeed)
         currentTime = 0.0f;
 bool AMainDirector::isAlive(FVector position) const
     return _cells[position];
 uint32 AMainDirector::GetAdjacentCellsAlive(FVector position) const
     uint32 alive = 0;
     const uint32 x0 = FMath::Clamp<float>(position.X - 1, 0, Size.X - 1);
     const uint32 x1 = FMath::Clamp<float>(position.X + 1, 0, Size.X - 1);
     const uint32 y0 = FMath::Clamp<float>(position.Y - 1, 0, Size.Y - 1);
     const uint32 y1 = FMath::Clamp<float>(position.Y + 1, 0, Size.Y - 1);
     const uint32 z0 = FMath::Clamp<float>(position.Z - 1, 0, Size.Z - 1);
     const uint32 z1 = FMath::Clamp<float>(position.Z + 1, 0, Size.Z - 1);
     uint32 x, y, z;
     for (x = x0; x <= x1; x++)
         for (y = y0; y <= y1; y++)
             for (z = z0; z <= z1; z++)
                 alive += isAlive(FVector(x, y, z));
     return alive;
 void AMainDirector::UpdateGrid()
     TMap<FVector, bool> newGrid = _cells;
     uint32 alives;
     for (auto& pair : newGrid)
         alives = GetAdjacentCellsAlive(pair.Key);
         if (pair.Value == true)
             if (alives < 7 || alives > 10)
                 pair.Value = false;
             if (alives >= 10 && alives <= 12)
                 pair.Value = true;
     _cells = newGrid;

Now, whenever I try to run this code, Unreal crashes and shows an error report. I'd like to know of a debugging method on how to prevent this. Thanks for the reply and kudos to people finding the problem in this code (I assume it has to do with the TMaps).

Product Version: UE 4.8
more ▼

asked Jul 06 '15 at 12:39 AM in C++ Programming

avatar image

21 1 2 4

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

1 answer: sort voted first
  1. In Visual Studio, set your Solution Configuration to "Debug Editor"

  2. Build your project.

  3. Make sure Unreal editor is running.

  4. From the visual studio menu, select Debug > Attach to Process, and choose the running Unreal editor.

  5. Run your level from within the editor, and now that the debugger is attached, any breakpoint you've placed in Visual Studio should now be hit.

more ▼

answered Jul 06 '15 at 01:29 AM

avatar image

81 2 5 15

avatar image lucas92 Jul 06 '15 at 02:26 AM

Thanks for the quick answer.

Ok, it appears that the line _cells[index] = false; is causing the crash. The editor however crashed and I need to restart it. Is this normal?

alt text

unreal_crash.png (50.3 kB)
avatar image KeirBlackDelta Jul 06 '15 at 04:02 AM

Yes, that's normal, unfortunately! Failed assertions will cause the editor to crash.

avatar image virtual_method May 12 '17 at 11:41 AM

Not working for me. You mean Debug Game Editor? Game Editor is not available anymore.

(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