Unreal show me line “TilePtr& tile = m_tiles[getTileIndex(pos)];” in TileBlock::getOrCreate()
TileBlock.h
#pragma once
#include "Tile.h"
class RPGONLINE_API TileBlock
{
public:
TileBlock();
const TilePtr& create(const Position& pos);
const TilePtr& getOrCreate(const Position& pos);
const TilePtr& get(const Position& pos) { return m_tiles[getTileIndex(pos)]; }
void remove(const Position& pos) { m_tiles[getTileIndex(pos)] = nullptr; }
uint getTileIndex(const Position& pos) { return ((pos.y % 32) * 32) + (pos.x % 32); }
const TArray<TilePtr>& getTiles() const { return m_tiles; }
private:
TArray<TilePtr> m_tiles;
};
TileBlock.cpp
#include "TileBlock.h"
TileBlock::TileBlock()
{
g_logger.debug("TILEBLOCK CONSTRUCTOR");
m_tiles.Empty();
//m_tiles.SetNum(1024);
m_tiles.Init(nullptr, 1024);
}
const TilePtr& TileBlock::create(const Position& pos)
{
TilePtr& tile = m_tiles[getTileIndex(pos)];
tile = TilePtr(new Tile(pos));
g_logger.debug(FString::Printf(TEXT("Tile Created Index: %d, pos %d %d %d"), getTileIndex(pos), pos.x, pos.y, pos.z));
return tile;
}
const TilePtr& TileBlock::getOrCreate(const Position& pos)
{
TilePtr& tile = m_tiles[getTileIndex(pos)]; //LINE WITH ERROR
if (!tile)
tile = TilePtr(new Tile(pos));
return tile;
}
Error appears when I call m_tiles
What I am doing wrong here?