I’m in a project for my internship and they asked me to change some assets. (basically, switch some prefabs for another prefab).
So, these prefabs were tagged with a different tag, therefore I tagged one of the new prefabs that they gave me with the tag that the old prefabs had (the one that I had to put for the old one). Next, to that, I started to add the components that the old prefabs have to the new prefab. I added the scripts that they had been attached to the older ones (So basically at this point you can be sure that I was creating some clones of over older prefabs.) The thing is, when I plug the prefabs to the GameManager. I get the NullReferenceException error. Now I will copy/paste the console error:
Console Error:
NullReferenceException: Object reference not set to an instance of an object
_Script.Manager.Level12.JellyfishManager.CreateInitialJellyfish (Level12.Words word, System.Single withdealay) (at Assets/_Script/Manager/Level12/JellyfishManager.cs:99)
_Script.Manager.Level12.GameManager.CreateInitialJellyfish () (at Assets/_Script/Manager/Level12/GameManager.cs:128)
_Script.Manager.Level12.MainMenuManager.<Awake>m__0 () (at Assets/_Script/Manager/Level12/MainMenuManager.cs:70)
UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:154)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:52)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()
When I click the error to see where the error should be, it prompted to the JellyFishManager.cs, more accurately this function: (component.SetColor() is where the error is pointing.
public void CreateInitialJellyfish(Words word, float withdealay = 0f)
{
//jellyfish Object .
GameObject jellyfish = null;
//create jellyfish .
jellyfish = Instantiate(JellyfishArray[(int) JellyFishType.KingJellyFish]);
//Rename the object
jellyfish.name = "BigInitialJellyfish";
//set tag
jellyfish.tag = "JellyFish";
//get component .
var component = jellyfish.GetComponent<InitialJellyFish>();
//set color.
component.SetColor();
//set word.
component.SetWord(word);
//if wuth delay parameter is not overwritten.
//component.AnimateJellyfish(!(withdealay <= 0f) ? withdealay : InitialJellyfishkAnimationDelay);
}
The function derives from the InitialJellyFish.cs script, more accurately, this function:
public void SetColor()
{
//Jellyfish color .
var jellyfishColor = JellyfishColors[Random.Range(0, JellyfishColors.Count)];
//Text color .
var jellyfishTextColor = JellyfishTextColor[Random.Range(0, JellyfishTextColor.Count)];
//set the color of text and Jellyfish .
SetColor(jellyfishColor, jellyfishTextColor);
}
And that is where I lost the trace of the error, and my thoughts, lol. If somebody is so kind of helping me with this. If you guys want more details about the project I can MP you so I can work this out and move on with the other problems.