0 votes

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:


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)
Godot version 3.3.4 (Custom version but doesn't have changes in the API)
in Engine by (30 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.