Z
Z
zeni1agent2022-01-28 19:17:17
Unity
zeni1agent, 2022-01-28 19:17:17

Object reference not set to an instance of an object. What could be the problem?

I am trying to repeat the code from this video

CardInfoScr.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;



public class CardInfoScript : MonoBehaviour
{
  public Card SelfCard;
  public Image Logo;
  public TextMeshProUGUI Name;
  
  public void ShowCardInfo(Card card)
  {
    SelfCard = card;
    
    
    
    // Ошибка
    Name.text = card.Name;
    
    
    Logo.sprite = card.Logo;
    Logo.preserveAspect = true;
    
    
    
  }
  
  private void Start(){
    ShowCardInfo(CardManager.AllCards[transform.GetSiblingIndex()]);
  }
  
  
}


But I am getting an error

NullReferenceException: Object reference not set to an instance of an object
CardInfoScript.ShowCardInfo (Card card) (at Assets/Scripts/CardInfoScript.cs:22)
CardInfoScript.Start () (at Assets/Scripts/CardInfoScript.cs:33)

Can anyone explain what is the reason?
I understand that the Card Pixel should have the names Name and Logo
But I have them.
61f416e89b060339773759.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2022-01-28
@zeni1agent

Must be Name and Logo

Not the names of objects in the scene should be, but the variables in the script should contain references to objects.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question