So this has been driving me nuts for the past 4.5 hours.
I’m trying to Instantiate a prefab from a stack that has GameObjects pushed in it.
The error I’m getting is: Assets\Stack\stack_instantiate.cs(29,25): error CS1503: Argument 1: cannot convert from ‘object’ to ‘UnityEngine.Object’
Replacing stack.Pop() in Instantiate with cube_obj works great, but for some reason I’m getting this error when using stack.Pop().
Meanwhile, Debug.Log() shows exactly the same for both cube_obj & stack.Pop()'ing the cube_obj.
Only thing I found online was to use as GameObject at the end of Instantiate, but it didn’t work…
Using as GameObject just returns one more error, this one: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class stack_instantiate : MonoBehaviour
{
// Object spawn object
public GameObject spawner;
// Objects database that will/can be pushed into stack
public GameObject cube_obj;
// Create stack
Stack stack = new Stack();
// Start is called before the first frame update
void Start()
{
stack.Push(cube_obj);
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown("space") & stack.Count != 0)
{
Instantiate(stack.Pop(), spawner.transform.position, Quaternion.identity);
Debug.Log(stack.Pop());
}
}
}