Download

Array index out of bounds: 0 from an array of size 0

keep getting this error after “launch”, but in simulation everything works perfect, i get every single string from array with no exception. Heres code:


        TArray<FString> APlayerController::GetLocalizedTextFromFile(FString filename)
        {
            FString FilePath;
            TArray<FString> TextLines;
            switch (CurrentLanguage)
            {
            case Language::Russian:
                FilePath = (FPaths::ProjectDir() + "Content/Localization/" + filename + "Russian.txt");
                break;
            case Language::English:
                FilePath = (FPaths::ProjectDir() + "Content/Localization/" + filename + "English.txt");
                break;
            default:
                FilePath = (FPaths::ProjectDir() + "Content/Localization/" + filename + "Russian.txt");
                break;
            }
            FFileHelper::LoadANSITextFileToStrings(*FilePath, NULL, TextLines);
            return TextLines;
        }



void FSkills::UpdateSkillWidgetName(APlayerController* controller, Skill::Type skill)
{
    FString namestring = FString::FromInt(skill) + ", " + controller->GetLocalizedTextFromFile("SkillNames")[skill];
    controller->SetSkillWidgetName(namestring);
}

there is 58 lines in text file, and when i simulate i get 58 words from TextLines array, but when i “launch” or “package project” i get this error when im trying to access any index from 0 to 57.

Have you check the existence of file in FilePath while in package mode?

no i didnt, i thought everything from content folder is getting packed, u were right, after i copied textfiles to package dir it worked well.
is there a way to add those files into project somehow to include them in package automaticly?

You can configure this in “project settings” - “Packaging” - “Additional None-Asset Directory to Copy”