函数未在虚幻中调用

时间:2015-03-10 06:28:29

标签: c++ unreal-engine4

我是Unreal的新手。我是一个研究项目的一部分,我正在尝试更好地学习引擎,但是有些事情让我陷入了很长一段时间。我在.h文件中声明了一个私有函数GetGrids。我试图在.cpp文件中调用它,但控件永远不会进入该函数。我在该函数中放置了一个断点,它根本没有被击中。我尝试重新启动visual studio,重建解决方案,但似乎没有任何工作。

#include "RoboRev_Win.h"
#include "MapsManager.h"

AMapsManager::AMapsManager(const FObjectInitializer& ObjectInitializer)
    :Super(ObjectInitializer)
{
    m_row = MAP_SIZE;
    m_column = MAP_SIZE;
    m_startPoint = FVector(0, 0, 90);
    m_IsMapCreated = false;
    PrimaryActorTick.bStartWithTickEnabled = true;
}

void AMapsManager::Tick(float DeltaSeconds)
{
    Super::Tick(DeltaSeconds);
    if (!m_IsMapCreated)
        CreateMap();
}

AGrid* AMapsManager::GetGridWithID(int _ID)
{
    for (int i = 1; i <= GRID_SIZE*GRID_SIZE; i++)
    {
        AGrid *_Grid = m_Grids[i];
        if (_Grid->ID == _ID)
        {
            return _Grid;
        }
    }
    return NULL;
}

void AMapsManager::GetGrids()
{
    int a, b, c;
    a = 1;
    b = 2;
    c = 3;
    int sum;
    sum = a + b + c;
    printf("");
    printf("");
}

void AMapsManager::CreateMap()
{
    UWorld* const _World = GetWorld();
    if (_World)
    {
        m_IsMapCreated = true;

        FActorSpawnParameters _Parameters;
        _Parameters.Owner = this;
        _Parameters.Instigator = Instigator;

        FVector _SpawnPosition;

        FRotator _Rotator(0, 0, 0);

        _SpawnPosition = FVector(0, 0, 0);

        originalX = _SpawnPosition.X - ((MAP_SIZE / 2)*GRID_SIZE);
        _SpawnPosition.X = originalX;
        _SpawnPosition.Y = originalX;

        _CurrentID = 1;
        for (int i = 1; i <= m_row; i++)
        {
            for (int j = 1; j <= m_column; j++)
            {
                AGrid *_Grid = static_cast<AGrid *>(_World->SpawnActor(m_GridPawn, &_SpawnPosition, &_Rotator, _Parameters));
                _Grid->ID = _CurrentID;
                m_Grids.push_back(_Grid);
                _SpawnPosition.X += GRID_SIZE;
                _CurrentID++;
            }
            _SpawnPosition.Y += GRID_SIZE;
            _SpawnPosition.X = originalX;
        }
    }
    int _MapIDs[] = { 1, 2, 3, 4, 5, 10, 15, 20, 25 };
    int k = 9;
    for (int l = 0; l < k; l++)
    {
        //AGrid *_Grid = GetGridWithID(_MapIDs[l]);
        //_Grid->ChangeMaterial();
        this->GetGrids();
    }
}

不要介意这个功能在做什么。它只是一个测试功能。

这是.h文件中的声明

private:
       void GetGrids();

请帮忙!

1 个答案:

答案 0 :(得分:2)

您的Visual Studio编译器配置为非常积极地优化您的函数的代码和调用。由于GetGrids()方法对正在运行的程序没有任何影响,因此编译器只会完全取消调用或内联诸如print之类的内容。 即使使用断点进行调试,也无法跳转到编译器优化的方法。

尝试在您的函数中添加这样的内容,以便在运行的引擎中看到它。

UE_LOG(LogExec, Warning, TEXT("GetGrids() was called."));