Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
-2
Question by kbeaud · Nov 17, 2012 at 06:58 PM · errornullobject reference

CAN SOMEONE FINALLY HELP ME!

I have asked A LOT of people, but no one can seem to help. I am sooo stuck it hurts my head, so please help me here. I need to fix my object reference not set to an instance of an object code... Here is one code( the (>) is where the problem shows):

     private void SetupSkillModifiers() {
        //Melee Offence
        ModifyingAttribute MeleeOffenceModifier1 = new ModifyingAttribute();
        ModifyingAttribute MeleeOffenceModifier2 = new ModifyingAttribute();
 
        MeleeOffenceModifier1.attribute = GetPrimaryAttribute((int)AttributeName.Might);
        MeleeOffenceModifier1.ratio = .33f;
 
        MeleeOffenceModifier2.attribute = GetPrimaryAttribute((int)AttributeName.Nimbleness);
        MeleeOffenceModifier2.ratio = .33f;
 
        (>)GetSkill((int)SkillName.Melee_Offence).AddModifier(MeleeOffenceModifier1);
        GetSkill((int)SkillName.Melee_Offence).AddModifier(MeleeOffenceModifier2);

as well as this section:

     private void DisplaySkills() {
         for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
             GUI.Label(new Rect(250, 40 + (cnt * 25), 100, 25), ((SkillName)cnt).ToString());
             GUI.Label(new Rect(355, 40 + (cnt * 25), 30, 25), _toon.GetSkill(cnt).AdjustedBaseValue.ToString());
         }

I think this code might be the source of the problem I am having:

 using UnityEngine;
 using System.Collections;
 using System;          //added to access Enum Class
 
 public class BaseCharacter : MonoBehaviour {
     private string _name;
     private int _level;
     private uint _freeExp;
 
     private Attribute[] _primaryAttribute;
     private Vital[] _vital;
     private Skill[] _skill;
 
     public void Awake() {
        _name = string.Empty;
        _level = 0;
        _freeExp = 0;
 
        _primaryAttribute = new Attribute[Enum.GetValues(typeof(AttributeName)).Length];
        _vital = new Vital[Enum.GetValues(typeof(VitalName)).Length];
        _skill = new Skill[Enum.GetValues(typeof(SkillName)).Length];

And Finally I added this code, which holds the SkillName variable. I believe it has some part in the problem. So heres the code:

 public class Skill : ModifiedStat {
     private bool _known;
 
     public Skill() {
        _known = false;
        ExpToLevel = 25;
        LevelModifier = 1.15f;
     }
 
     public bool Known {
        get{ return _known; }
        set{ _known = value; }
     }
 }
 
 public enum SkillName {
     Melee_Offence,
     Melee_Defence,
     Ranged_Offence,
     Ranged_Defence,
     Magic_Offence,
     Magic_Defence
 }

I hope all of these codes will help you guys help me... So if you don't think this is enough I have other codes that might help. ;)

Comment
Add comment
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

3 Replies

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

Answer by Democre · Nov 20, 2012 at 12:35 AM

You are never calling SetupPrimarySkills before calling SetupSkillModifiers. Therefore your _skills array is still an array of null objects. Therefore when you call GetSkill it returns null.

Comment
Add comment · 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
0

Answer by Loius · Nov 17, 2012 at 07:31 PM

Your GetSkill function is returning null.

Comment
Add comment · Show 10 · 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 kbeaud · Nov 17, 2012 at 07:35 PM 0
Share

How do I fix that?

avatar image Loius · Nov 17, 2012 at 08:43 PM 1
Share

$$anonymous$$ake your GetSkill function return a value which is not null.

(hint: Since GetSkill isn't in the code here, that's as helpful as anyone can be)

avatar image kbeaud · Nov 17, 2012 at 08:46 PM 0
Share

Ok so I will find it... Check back in oh 15-20 $$anonymous$$ and I should have it

avatar image kbeaud · Nov 17, 2012 at 09:10 PM 0
Share

Alrite well I have no variable for GetSkill... I just have a variable for Skill...

avatar image kbeaud · Nov 17, 2012 at 09:18 PM 0
Share

Can you help me write something to fix my problem? All the skills are listed in one of my scripts above, but can you make it so i'm able to add more Skills and not have to change the code? I would highly appreciate this thanks!

Show more comments
avatar image
0

Answer by kbeaud · Nov 18, 2012 at 01:30 AM

here is the GetSkill:

     public Skill GetSkill(int index) {
        return _skill[index];
     }
 
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 Loius · Nov 18, 2012 at 03:28 AM 0
Share

This is a comment, not an answer.

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

11 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

Related Questions

NullReferenceException: Object reference not set to an instance of an object 1 Answer

Error in script 1 Answer

Object Reference Error On Camera Script 1 Answer

Whats wrong with this simple code? 2 Answers

How do I fix this error in my code 2 Answers


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