- Home /
I solved it somehow
Resources folder items not in the build
Hi I made some images and audio-mixers in resources folder to use later. As in the title, after the build. My items not in the folder and some of my scripts are giving error, because of that. How can I fix this issue?
edit(moved from comment)
If someone wonders to look my code (Maybe code is messed. But so far works great and I'm focusing to implementing. After that I'll do the cleanup )
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.EventSystems;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;
public class Main_Menu : MonoBehaviour
{
internal GameObject[] _buttons, _texts, _sliders, _shutters;
static TextMeshProUGUI _screentext;
static int _sliderIndex;
static GameObject[] _sound_sliders;
internal TextMeshProUGUI _vsynctext, _graphicstext, _AA_result, _AA_sub_result;
public List<GameObject> _graphicsbuttonslist, _vsyncbuttonslist, _AA_buttonslist, _AA_subbuttonslist;
internal HDAdditionalCameraData _camera;
Resolution[] _resolutions;
public Dropdown _res_dropdown;
AudioMixer[] _mixer;
public GameObject[] _changer_buttons, _ReMappers;
Slider _mouse_slider;
Image _img;
void Start()
{
_shutters = GameObject.FindGameObjectsWithTag("Shutters");
#region Buttons Finder
_AA_buttonslist.Insert(0, GameObject.Find("None"));
_AA_buttonslist.Insert(1, GameObject.Find("Fxaa"));
_AA_buttonslist.Insert(2, GameObject.Find("Taa"));
_AA_buttonslist.Insert(3, GameObject.Find("Smaa"));
_AA_subbuttonslist.Insert(0, GameObject.Find("AA_Low"));
_AA_subbuttonslist.Insert(1, GameObject.Find("AA_Medium"));
_AA_subbuttonslist.Insert(2, GameObject.Find("AA_High"));
_graphicsbuttonslist.Insert(0, GameObject.Find("Low"));
_graphicsbuttonslist.Insert(1, GameObject.Find("Medium"));
_graphicsbuttonslist.Insert(2, GameObject.Find("High"));
_vsyncbuttonslist.Insert(0, GameObject.Find("No_Limit"));
_vsyncbuttonslist.Insert(1, GameObject.Find("60fps"));
_vsyncbuttonslist.Insert(2, GameObject.Find("30fps"));
#endregion
_img = GameObject.Find("Background_Image").gameObject.GetComponent<Image>();
_img.sprite = Resources.Load<Sprite>("apartment");
_mixer = new AudioMixer[Universal_Properties._mixer_counter.Length];
_mixer[0] = Resources.Load<AudioMixer>("Sounds/Ambient_Mixer");
_mixer[1] = Resources.Load<AudioMixer>("Sounds/Effects_Mixer");
_mixer[2] = Resources.Load<AudioMixer>("Sounds/Music_Mixer");
_mixer[3] = Resources.Load<AudioMixer>("Sounds/Other_Mixer");
_sliders = GameObject.FindGameObjectsWithTag("Slider_CSS");
_changer_buttons = GameObject.FindGameObjectsWithTag("Changer_Buttons").OrderBy(go => go.name).ToArray();
_ReMappers = GameObject.FindGameObjectsWithTag("ReMappers").OrderBy(go => go.name).ToArray();
_sound_sliders = GameObject.FindGameObjectsWithTag("Slider").OrderBy(go => go.name).ToArray();
_buttons = GameObject.FindGameObjectsWithTag("Main_Buttons");
_texts = GameObject.FindGameObjectsWithTag("Main_Texts");
_graphicstext = GameObject.Find("Graphics_Result").GetComponent<TextMeshProUGUI>();
_vsynctext = GameObject.Find("Vsync_Result").GetComponent<TextMeshProUGUI>();
_screentext = GameObject.Find("Screen_Result").GetComponent<TextMeshProUGUI>();
_AA_result = GameObject.Find("AA_Result").GetComponent<TextMeshProUGUI>();
_AA_sub_result = GameObject.Find("AA_Sub_Result").GetComponent<TextMeshProUGUI>();
_camera = GameObject.Find("Main Camera").gameObject.GetComponent<HDAdditionalCameraData>();
_mouse_slider = GameObject.Find("Mouse_Slider").gameObject.GetComponent<Slider>();
_mouse_slider.value = Universal_Properties._mouse_speed;
foreach (GameObject r in _buttons )
{
Image b = r.GetComponent<Image>();
b.sprite = null;
b.raycastTarget = Universal_Properties._raycasttarget;
b.color = new Color32(188, 188, 188, 255);
}
foreach (GameObject r in _texts)
{
TextMeshProUGUI b = r.GetComponent<TextMeshProUGUI>();
b.color = Color.white;
b.alignment = TextAlignmentOptions.Center;
b.fontSize = 23;
}
foreach (GameObject r in _sliders)
{
Image b = r.GetComponent<Image>();
b.sprite = null;
}
switch (Universal_Properties._camera_AA)
{
case HDAdditionalCameraData.AntialiasingMode.None:
{
_AA_result.text = _AA_buttonslist[0].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = HDAdditionalCameraData.AntialiasingMode.None;
break;
}
case HDAdditionalCameraData.AntialiasingMode.FastApproximateAntialiasing:
{
_AA_result.text = _AA_buttonslist[1].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = HDAdditionalCameraData.AntialiasingMode.FastApproximateAntialiasing;
break;
}
case HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing:
{
_AA_result.text = _AA_buttonslist[2].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing;
switch (Universal_Properties._TAA_Quality)
{
case HDAdditionalCameraData.TAAQualityLevel.Low:
{
_AA_sub_result.text = _AA_subbuttonslist[0].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = (HDAdditionalCameraData.AntialiasingMode)HDAdditionalCameraData.TAAQualityLevel.Low;
break;
}
case HDAdditionalCameraData.TAAQualityLevel.Medium:
{
_AA_sub_result.text = _AA_subbuttonslist[1].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = (HDAdditionalCameraData.AntialiasingMode)HDAdditionalCameraData.TAAQualityLevel.Medium;
break;
}
case HDAdditionalCameraData.TAAQualityLevel.High:
{
_AA_sub_result.text = _AA_subbuttonslist[2].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = (HDAdditionalCameraData.AntialiasingMode)HDAdditionalCameraData.TAAQualityLevel.High;
break;
}
}
break;
}
case HDAdditionalCameraData.AntialiasingMode.SubpixelMorphologicalAntiAliasing:
{
_AA_result.text = _AA_buttonslist[3].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = HDAdditionalCameraData.AntialiasingMode.SubpixelMorphologicalAntiAliasing;
switch (Universal_Properties._SMAA_Quality)
{
case HDAdditionalCameraData.SMAAQualityLevel.Low:
{
_AA_sub_result.text = _AA_subbuttonslist[0].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = (HDAdditionalCameraData.AntialiasingMode)HDAdditionalCameraData.SMAAQualityLevel.Low;
break;
}
case HDAdditionalCameraData.SMAAQualityLevel.Medium:
{
_AA_sub_result.text = _AA_subbuttonslist[1].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = (HDAdditionalCameraData.AntialiasingMode)HDAdditionalCameraData.SMAAQualityLevel.Medium;
break;
}
case HDAdditionalCameraData.SMAAQualityLevel.High:
{
_AA_sub_result.text = _AA_subbuttonslist[2].GetComponentInChildren<TextMeshProUGUI>().text;
_camera.antialiasing = (HDAdditionalCameraData.AntialiasingMode)HDAdditionalCameraData.SMAAQualityLevel.High;
break;
}
}
break;
}
}
switch(Universal_Properties._quality_level)
{
case 0:
{
_graphicstext.text = _graphicsbuttonslist[0].GetComponentInChildren<TextMeshProUGUI>().text;
break;
}
case 1:
{
_graphicstext.text = _graphicsbuttonslist[1].GetComponentInChildren<TextMeshProUGUI>().text;
break;
}
case 2:
{
_graphicstext.text = _graphicsbuttonslist[2].GetComponentInChildren<TextMeshProUGUI>().text;
break;
}
}
switch(Universal_Properties._vsync_lvl)
{
case 0:
{
_vsynctext.text = _vsyncbuttonslist[0].gameObject.GetComponentInChildren<TextMeshProUGUI>().text;
break;
}
case 1:
{
_vsynctext.text = _vsyncbuttonslist[1].gameObject.GetComponentInChildren<TextMeshProUGUI>().text;
break;
}
case 2:
{
_vsynctext.text = _vsyncbuttonslist[2].gameObject.GetComponentInChildren<TextMeshProUGUI>().text;
break;
}
}
for (int i = 0; i < _sound_sliders.Length; i++)
{
_sound_sliders[i].gameObject.GetComponent<Slider>().onValueChanged.AddListener(delegate { SetVolume(); });
}
for (int i = 0; i < _changer_buttons.Length; i++)
{
_changer_buttons[i].gameObject.GetComponent<Button>().onClick.AddListener(delegate { ReMapper(); });
Image b = _changer_buttons[i].GetComponent<Image>();
b.sprite = null;
b.raycastTarget = Universal_Properties._raycasttarget;
b.color = new Color32(188, 188, 188, 255);
}
for (int i = 0; i < _ReMappers.Length; i++)
{
}
#region Scrrencheck
if (Screen.fullScreen)
{
ScreenModeChecker(true);
}
else
{
ScreenModeChecker(false);
}
#endregion
StartCoroutine(Shutters());
#region Resolution listing
_resolutions = Screen.resolutions;
_res_dropdown.ClearOptions();
List<string> options = new List<string>();
int currenResolutionIndex = 0;
for (int i = 0; i < _resolutions.Length; i++)
{
if (_resolutions[i].refreshRate > 59)
{
string option = _resolutions[i].width + " x " + _resolutions[i].height + " " + _resolutions[i].refreshRate + " Hz";
options.Add(option);
}
if (_resolutions[i].width == Screen.currentResolution.width && _resolutions[i].height == Screen.currentResolution.height)
{
currenResolutionIndex = i;
}
}
_res_dropdown.AddOptions(options);
_res_dropdown.value = currenResolutionIndex;
_res_dropdown.RefreshShownValue();
#endregion //üstünde durulacak
}
private void ReMapper()
{
}
internal static void teller(GameObject obj)
{
for (int i = 0; i < _sound_sliders.Length; i++)
{
if (_sound_sliders[i] == obj)
{
_sliderIndex = i;
}
}
}
internal static void ScreenModeChecker(bool chk)
{
if (chk == true)
_screentext.text = Universal_Properties._fullscreen;
else
_screentext.text = Universal_Properties._windowed;
}
public void AA_changer()
{
switch (EventSystem.current.currentSelectedGameObject.name)
{
case "None":
{
_camera.antialiasing = HDAdditionalCameraData.AntialiasingMode.None;
break;
}
case "Fxaa":
{
_camera.antialiasing = HDAdditionalCameraData.AntialiasingMode.FastApproximateAntialiasing;
break;
}
case "Taa":
{
_camera.antialiasing = HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing;
break;
}
case "Smaa":
{
_camera.antialiasing = HDAdditionalCameraData.AntialiasingMode.SubpixelMorphologicalAntiAliasing;
break;
}
}
_AA_result.text = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TextMeshProUGUI>().text;
Universal_Properties._camera_AA = _camera.antialiasing;
}
public void Sub_AA_changer()
{
if(Universal_Properties._camera_AA == HDAdditionalCameraData.AntialiasingMode.SubpixelMorphologicalAntiAliasing)
{
switch (EventSystem.current.currentSelectedGameObject.name)
{
case "AA_High":
{
Universal_Properties._SMAA_Quality = HDAdditionalCameraData.SMAAQualityLevel.High;
break;
}
case "AA_Medium":
{
Universal_Properties._SMAA_Quality = HDAdditionalCameraData.SMAAQualityLevel.Medium;
break;
}
case "AA_Low":
{
Universal_Properties._SMAA_Quality = HDAdditionalCameraData.SMAAQualityLevel.Low;
break;
}
}
_AA_sub_result.text = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TextMeshProUGUI>().text;
_camera.SMAAQuality = Universal_Properties._SMAA_Quality;
}
else if (Universal_Properties._camera_AA == HDAdditionalCameraData.AntialiasingMode.TemporalAntialiasing)
{
switch (EventSystem.current.currentSelectedGameObject.name)
{
case "AA_High":
{
Universal_Properties._TAA_Quality = HDAdditionalCameraData.TAAQualityLevel.High;
break;
}
case "AA_Medium":
{
Universal_Properties._TAA_Quality = HDAdditionalCameraData.TAAQualityLevel.Medium;
break;
}
case "AA_Low":
{
Universal_Properties._TAA_Quality = HDAdditionalCameraData.TAAQualityLevel.Low;
break;
}
}
_AA_sub_result.text = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TextMeshProUGUI>().text;
_camera.TAAQuality = Universal_Properties._TAA_Quality;
}
}
public void vsyncchanger()
{
switch (EventSystem.current.currentSelectedGameObject.name)
{
case "60fps":
{
QualitySettings.vSyncCount = (int)vsync_lvl.Highfps;
break;
}
case "30fps":
{
QualitySettings.vSyncCount = (int)vsync_lvl.Lowfps;
break;
}
case "No_Limit":
{
QualitySettings.vSyncCount = (int)vsync_lvl.NoLimit;
break;
}
}
_vsynctext.text = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TextMeshProUGUI>().text;
Universal_Properties._vsync_lvl = QualitySettings.vSyncCount;
}
public void graphicspresent()
{
switch(EventSystem.current.currentSelectedGameObject.name)
{
case "High":
{
QualitySettings.SetQualityLevel((int)present_lvl.High, true);
break;
}
case "Medium":
{
QualitySettings.SetQualityLevel((int)present_lvl.Medium, true);
break;
}
case "Low":
{
QualitySettings.SetQualityLevel((int)present_lvl.Low, true);
break;
}
}
Universal_Properties._quality_level = QualitySettings.GetQualityLevel();
_graphicstext.text = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TextMeshProUGUI>().text;
}
public void Screenmode_changer()
{
if(Screen.fullScreenMode == FullScreenMode.FullScreenWindow)
{
Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, FullScreenMode.Windowed); //Çözünürlükler ayarlanacak
_screentext.text = Universal_Properties._windowed;
}
else
{
Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, FullScreenMode.FullScreenWindow);
_screentext.text = Universal_Properties._fullscreen;
}
}
public void resolution(int Index)
{
Debug.Log(Index);
Resolution resolution = _resolutions[Index];
if (Screen.fullScreenMode == FullScreenMode.FullScreenWindow)
{ Screen.SetResolution(resolution.width, resolution.height, FullScreenMode.FullScreenWindow); }
else
{ Screen.SetResolution(resolution.width, resolution.height, FullScreenMode.Windowed); }
} //üstünde durulacak
public void SetVolume()
{
_mixer[_sliderIndex].SetFloat(Universal_Properties._fake_enums[_sliderIndex], Mathf.Log10(_sound_sliders[_sliderIndex].gameObject.GetComponent<Slider>().value) * Universal_Properties._volume_percentage);
}
IEnumerator Shutters()
{
yield return null;
foreach (GameObject r in _shutters)
{
r.SetActive(false);
}
}
}
Answer by dorusoftware · Apr 16, 2021 at 01:22 AM
not sure what is the problem in your case but turns out using Resources folder in unity is getting deprecated and you should use instead this method descrived here
https://docs.unity3d.com/Packages/com.unity.addressables@1.17/manual/index.html
better leave those resouces folder behind and learn this new method that appears to be better
Looks horrible to learn and practically use. I'll learn when time comes. Somehow my coding causing the problem, I don't know how but I'll find out.
you can check if the folder you have named is actually called Resources with capital R, sound supid but maybe this is the issue.
and maybe this new system I've linked messed up soemthing in your project, maybe is ON by default and broke the automatic packing of Resources folders
I found something while digging and debugging. Firstly, this one sometimes appearing the console. I don't $$anonymous$$d it, because it is happening sometimes ( UnityEngine.Rendering.DebugManager.UpdateActions () (at Library/PackageCache/com.unity.render-pipelines.core@10.4.0/Runtime/Debugging/DebugManager.Actions.cs:241) ). After that I looked up for solution in this site link text After the reimporting the assets. I found the real problem. That unity, only realized after the reimport. Something like this: get_isEditor (get_path if remember correctly) is not allowed to be called from a MonoBehaviour constructor" Error. Maybe I did a rookie mistake I don't know but I almost got it. I'll post an update later.
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Keeping item database 1 Answer
How add file to resources folder? 3 Answers