Question about an error:NullReferenceException: Object reference not set to an instance of an object
Options
Hello.
I'm trying to create objects using PhotonNetwork.Instantiate
public void Createcardpref(Card card, Transform hand)
{
GameObject cardGO = PhotonNetwork.Instantiate(Card.name, new Vector3(1600, -200), Quaternion.identity);
CardController cardC = cardGO.GetComponent<CardController>();
cardC.Init(card, hand == PlayerHand);
}
but when I try to call gameobject in CardController cardC = cardGO.GetComponent<CardController>(), it gets a null. Script attached to the gameobject in the inspector, usuall instantiate works normally. I do not understand what mistake I've done, so asking for help. Thanks for your responses
I'm trying to create objects using PhotonNetwork.Instantiate
public void Createcardpref(Card card, Transform hand)
{
GameObject cardGO = PhotonNetwork.Instantiate(Card.name, new Vector3(1600, -200), Quaternion.identity);
CardController cardC = cardGO.GetComponent<CardController>();
cardC.Init(card, hand == PlayerHand);
}
but when I try to call gameobject in CardController cardC = cardGO.GetComponent<CardController>(), it gets a null. Script attached to the gameobject in the inspector, usuall instantiate works normally. I do not understand what mistake I've done, so asking for help. Thanks for your responses
0
Answers
-
Your approach works imo. The only thing is that if those two info (card, hand == PlayerHand) have to be broadcast to all, those info can be send along with PhotonNetwork.Instantiate().0