I have little problem here.
I'm trying to get all the ScriptableObjects (named "InteractibleObjects") from Assets/Resources/InteractibleObjects and put them to the Dictionary (named "allInteractibleObjects"), but Unity throws NullReferenceExeption
on line with "Adding 'objectToAdd' to the 'allInteractibleObjects' Dictionary").
There is my code:
using System.Linq;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour {
public Dictionary<int, InteractibleObject> allInteractibleObjects;
public string[] allInteractibleObjetsNames;
void Start()
{
allInteractibleObjetsNames = Directory.GetFiles ("Assets/Resources/InteractibleObjects/", "*.asset")
.Select(Path.GetFileName)
.ToArray();// Getting files names
for (int i = 0; i < allInteractibleObjetsNames.Length; i++)
{
allInteractibleObjetsNames[i] = allInteractibleObjetsNames[i].Remove (allInteractibleObjetsNames[i].Length - 6);// Removing '.asset' from names
Object objectInFolder = Resources.Load("InteractibleObjects/" + allInteractibleObjetsNames[i]);// Finding 'InteractibleObjects' by the name from 'allInteractibleObjetsNames'
InteractibleObject objectToAdd = (InteractibleObject)objectInFolder;// From 'Object' to 'InteractibleObject'
allInteractibleObjects.Add (i, objectToAdd);// Adding 'objectToAdd' to the 'allInteractibleObjects' Dictionary
}
}
What should I do?