How to Kill() entity from another void?Solved
Hey guys... If I create a spawn using for example a void like this how do I kill it outside of this void? For example like this... (obviously this doesn't work)..

void OnServerInitialized()
{
    timer.Once(1, () =>
    {
        void spawn();
    });
    timer.Once(60, () =>
    {
        void despawn();
    });
}

void spawn()
{
    var lootbarrel = GameManager.server.CreateEntity("assets/bundled/prefabs/radtown/loot_barrel_1.prefab", 100, 15, 100);
    NextTick(() =>
    {
        lootbarrel.Spawn();
    });
}

void despawn()
{
    NextTick(() =>
    {
        lootbarrel.Kill();
    });
}

Thanks. :)
In response to TTRRust ():
Hey guys... If I create a spawn using for example a void like this how do I kill it outside of this...
you need to pass entity as argument to the method or make a global variable for it
In response to 2CHEVSKII ():
you need to pass entity as argument to the method or make a global variable for it
How to pass it?
In response to TTRRust ():
How to pass it?
You have to either call the despawn from the method where you've created entity
        void spawn()
        {
            var lootbarrel = GameManager.server.CreateEntity("assets/bundled/prefabs/radtown/loot_barrel_1.prefab", 
new UnityEngine.Vector3(100,15,100));
            NextTick(() =>
            {
                lootbarrel.Spawn();
            });
            despawn(lootbarrel);
        }

        void despawn(BaseEntity lootbarrel)
        {
            NextTick(() =>
            {
                lootbarrel.Kill();
            });
        }​
Either use a global variable
BaseEntity lootbarrel = GameManager.server.CreateEntity("assets/bundled/prefabs/radtown/loot_barrel_1.prefab", new UnityEngine.Vector3(100,15,100));
        void spawn()
        {
            NextTick(() =>
            {
                lootbarrel.Spawn();
            });
        }

        void despawn()
        {
            NextTick(() =>
            {
                lootbarrel.Kill();
            });
        }​
And btw you initializing vector3 the wrong way (I corrected it)
Thanks man. :)
Locked automatically