Resource Not Found Error

Hello, I posted a whie back about an issue I was having with presets and their parent objects. I decided to try a new approach that would not use any presets in hopes of avoiding these kinds of errors. I am now having an issue with the Resources folder that I have in that when the script I have attempts to retrieve a text resource from the folder, it cannot seem to find it. I looked up solutions, and it appears to me that I did exactly what the Unity manual explains, but it does not seem to be working for me (Here is the manual if you want to see it: Unity - Manual: Loading Resources at Runtime ). Am I missing something? Here is the code and error messages in case it is relevant.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class QuizManager : MonoBehaviour
{

    public GameObject canvas;

    GameObject CreateText(Transform canvas_transform, float x, float y, string text_to_print, int font_size, Color text_color)
    {
        Font arial;
        GameObject UItextGO = new GameObject("question");
        UItextGO.transform.SetParent(canvas_transform);

        RectTransform trans = UItextGO.AddComponent<RectTransform>();
        trans.anchoredPosition = new Vector2(x, y);

        arial = (Font)Resources.GetBuiltinResource(typeof(Font), "Roboto-Bold.ttf");

        Text text = UItextGO.AddComponent<Text>();
        text.font = arial;
        text.text = text_to_print;
        text.fontSize = font_size;
        text.color = text_color;

        return UItextGO;
    }  

    public void Start()
    {
        GameObject UItext = CreateText(canvas.transform, 100, 100, "Question 1", 24, Color.black);

       

    }

I’m not sure that call will work, and I also don’t think you want the .ttf in their either.

In any case, given you put the font in Resources correctly, you could simply use this:

arial = Resources.Load<Font>("Roboto-Bold");  // don't add .ttf suffix
1 Like

This fixed it for me, Thank you!

1 Like