Home > Enterprise >  "The name 'Data' does not exist in the current context"
"The name 'Data' does not exist in the current context"

Time:07-08

I am a beginner in C# programming. I am getting this error

The name 'Data' does not exist in the current context.

Trying to get data from my custom bundles and make game modable.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

public class GetBundleSc : MonoBehaviour
{
    public static void GetBundle()
    {
        if ( File.Exists(Application.streamingAssetsPath   "/dlc") )
        {
            Data.Bundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath   "/dlc");
        }
    }
}

CodePudding user response:

Your method / class does not have a variable "Data" declared inside it. Hence the "doesn't exist" you can see in the error message.

CodePudding user response:

In c# you need to declare a variable giving its type before you can use it. Declare it inside the function if you want it to disappear when the function finishes, or outside if you want it to persist. Try something like this:

Create the variable outside of the function:

AssetBundle bundle;

and you will be able to use it in the function:

bundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath   "/dlc");
  • Related