Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CosmoXD |
Hello, I’m trying to create a random map generator but when i’m trying to instantiate the Node2D
that has the required nodes using the instance()
function the application just freezes and quits.
Note: The ‘PackedScene’ that has the nodes is a std::vector<PackedScene*>
This is my code:
Player.cpp:
void Player::_ready()
{
ResourceLoader *resLoader = ResourceLoader::get_singleton();
this->obstacles = std::vector<PackedScene*>();
this->obstacles.push_back(cast_to<PackedScene>(resLoader->load("res://Prefabs/Obstacles/Obstacle 1.tscn").ptr()));
}
The part of the code that triggers the crash:
int selectedPiece = this->random(0, this->obstacles.size() - 1);
Godot::print(std::to_string(this->obstacles[selectedPiece] == nullptr).c_str());
if(this->obstacles[selectedPiece] != nullptr)
this->obstacles[selectedPiece]->instance();