Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by deanpackard · Dec 06, 2017 at 01:18 AM · uiarrayimage

My array of images is null for some reason?

I have an array of images to display cards in the players hand. It doesn't work, I get an error saying that the object reference is not set to an instance of an object.

 public int health;
 public int mana;
 public bool myTurn;
 private Card[] deck;
 private int cardsInHand;
 public Image[] hand;
 private PlayerCards playerCards;

 // Use this for initialization
 public void startGame(PlayerCards pc) {
     playerCards = pc;
     cardsInHand = 0;
     health = 30;
     mana = 0;
     deck = playerCards.getDeck();
     beginTurn();
 }



 public void Draw(int num)
 {
     for (int i = 0; i < num; i++)
     {
         //Draw a card
         Card card = playerCards.draw();
         //show an image
         hand[0].enabled = true;
         cardsInHand++;
     }
 }
Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image deanpackard · Dec 06, 2017 at 01:22 AM 0
Share

alt text

alt text

screen-shot-2017-12-05-at-61202-pm.png (31.6 kB)
screen-shot-2017-12-05-at-61226-pm.png (87.6 kB)
avatar image jchester07 deanpackard · Dec 06, 2017 at 01:25 AM 0
Share

Your hierarchy seems to be reddish. That could mean that it is a prefab and you deleted that prefab from the project folder.

Have you check those cards if they appear if you enable it in the inspector?

avatar image deanpackard jchester07 · Dec 06, 2017 at 01:41 AM 0
Share

Yeah, I did delete the prefab. I don't think that is the issue, I only made the prefab to see if that would help :p

Show more comments
avatar image deanpackard · Dec 06, 2017 at 01:53 AM 0
Share

@jchester07 I've updated it all to use prefabs of game objects. I still get the same weird error. alt text

alt text

screen-shot-2017-12-05-at-65302-pm.png (33.4 kB)
screen-shot-2017-12-05-at-65310-pm.png (82.3 kB)
avatar image jchester07 deanpackard · Dec 06, 2017 at 02:01 AM 0
Share

Which line does the error start?

avatar image deanpackard jchester07 · Dec 06, 2017 at 02:02 AM 0
Share

hand[cardsInHand].active = true; which I know is deprecated, but thats not the issue here.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by deanpackard · Dec 06, 2017 at 02:36 AM

I figured it out. It had stuff to do with initialization in this function of another class

 void Start () {
     playerCards = new PlayerCards();
     brodeCards = new BrodeCards();
     brodeCards.startGame();
     playerCards.startGame();
     pc.myFirstTurn = true;
 }

Before I wasn't getting an object reference to my player controller (pc), and so it wasn't running properly, its all good now though! Thanks everyone for your help.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kwergan · Dec 06, 2017 at 02:38 AM 0
Share

@deanpackard remember to mark your answer as correct :)

avatar image
0

Answer by Kwergan · Dec 06, 2017 at 02:06 AM

That particular error will occur usually if you forgot to assign the public variables with a value. Check in the inspector that you have assigned the deck and hand arrays.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image deanpackard · Dec 06, 2017 at 02:07 AM 0
Share

I did, but I may have missed something, look at the comments above :)

avatar image deanpackard deanpackard · Dec 06, 2017 at 02:21 AM 0
Share

@kwergan alt text

screen-shot-2017-12-05-at-72043-pm.png (83.2 kB)
avatar image Kwergan deanpackard · Dec 06, 2017 at 02:27 AM 0
Share

Anywhere in your code where you replace, remove, add items to the array? Arrays are not really scaleable, so the number you assign in the inspector is fixed. You can modify, but not add items. (Practically speaking) @deanpackard

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

131 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Images getting distorted -SOLVED 2 Answers

Image.enable not working properly 1 Answer

Change the button target image alpha 1 Answer

Instantiated UI objects with image components not appearing, rest of object works fine. 0 Answers

Get Mouse Position on an IMAGE (UI)? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges