- Home /
Question by
ragefordragons · Mar 11, 2018 at 04:26 PM ·
instantiateprefabsresourcesnullfolders
Prefab cant istiantiate through recources.load?
So I am trying to spawn a text thats a prefab like so, and for whatever reason it gives me 'The object you want to insitantiate is null' however I have triple checked that they are all named the exact same, and the prefab is named the exact same... Any ideas?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FloatingTextController : MonoBehaviour {
private static FloatingText popupText;
private static GameObject canvas;
public static void Initialize()
{
canvas = GameObject.Find("Canvas");
popupText = Resources.Load<FloatingText>("Prefabs/PopupTextParent");
}
public static void CreateFloatingText(string text, Transform location)
{
FloatingText instance = Instantiate(popupText);
instance.transform.SetParent(canvas.transform, false);
instance.SetText(text);
}
}
Comment
thats weird, I put a debug.log in there and its not showing up. However I am following a tutorial and this is not a problem for him...
Actually I figured it out, you were right!