+1 vote

I'm building an RTS game where there's a main, large scale map, where players command armies, and then when 2 armies collide it loads a battle in a small-scale battle simulator with a map corresponding to their location on the big map, kind of like Star Wars: Empire at War.
So I built the battle loader and it worked fine, but then I wrote a script for it to instantiate units depending on the armies and the navmesh completely broke.
I tried commenting out the script, and manually putting a single unit in the Battle_Loader scene and it worked, but instantiating them again did not.

I've double and triple checked the script, but here it is anyway:
extends Spatial

onready var Unit = preload("res://Unit.tscn")

var player_allegience = "Faction 1"

var units_to_spawn = {}
var units_instances = {}

var enemy_units_to_spawn = {}
var enemy_units_instances = {}

func begin_loading():


func spawn_units(units):
    for unit in units_to_spawn.size():
        # unit types
        if units_to_spawn[unit + 1] == "recon":
            var _unit = Unit.instance()
            get_node("Navigation").add_child( _unit, true)
            _unit.type = "recon"
        _unit.allegience = "Faction 1"
        units_instances[unit + 1] = _unit
        for enemy_unit in enemy_units_to_spawn.size():
        # enemy unit types
        if enemy_units_to_spawn[enemy_unit + 1] == "recon":
            var _enemy_unit = Unit.instance()
            get_node("Navigation").add_child(_enemy_unit, true)
            _enemy_unit.type = "recon"
        enemy_units_instances[enemy_unit + 1] = _enemy_unit

I'm not sure what's going on here, but if anyone could help that'd be great!

Edit: I also noticed that while instantiating AND using a manually created unit, they both break, including the one unaffected by script

(sorry if the indents are weird, it didn't paste correctly)

in Engine by (52 points)
edited by

This looks to be written in C#? My question is, would you happen to know how to write it in Godot format? I've been looking everywhere for a script that will allow me to spawn something without having manual input from the user. (Key press etc etc)

That isn't c#

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.