• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
Question by rasheedqw · Dec 26, 2014 at 01:59 PM · arrayscreenclassglitch

Script wont read array

i have a class with 4 variables. Another script puts this class into an array. the game wont read the array unless i minimize the screen the click on the array in the editor. Is this a glitch in the engine or did i do something wrong. Everything is marked public.

this is the class script

 #pragma strict
 
   public class ablities2 {
 
   public var name:String;
  
   public var pic:Texture2D;
 
   public var description:String;
 
   public var id:int;
 
   public var HaveAblity:boolean;
 
 }


This is the script that reads the class and puts it into an array

In the update i try to see if it reads the array. I entered the values in the inspector manually so i know ClassAbilties[0] exist but the script will not read it unless i minimize the screen then click the array ClassAbilties in the inspector

 public var RaceAbilties:ablities2[];
 
 public var ClassAbilties:ablities2[];
 
 public var PersonalityAbilties:ablities2[];
 
 public var SpecialityAbilties:ablities2[];
 
 public var Classes:Race_Combat_Class;
 
 var SlashPicUnlocked:Texture2D;
 
 var SlashPicLocked:Texture2D;
 
 var Slot1:String;
 
 var Slot2:String;
 
 var Slot3:String;
 
 var Slot4:String;
 
 function Awake(){
 Classes=transform.GetComponent(Race_Combat_Class);
 ClassAbilties= new ablities2[5];
 
 }
 
 
 function Update() {
 
 
 if(ClassAbilties[0]){
 print("the program is reading this");
 GiveSkillLine();
 }
 }
 
 
 
 function GiveSkillLine(){
 
 if(Classes.Warrior){
 
 //ablity 1
     ClassAbilties[0].name="Leap Slash";
     ClassAbilties[0].description="Jump Above The Enemy And Slashes Down";
     if(ClassAbilties[0].HaveAblity){
     ClassAbilties[0].pic=SlashPicUnlocked;
     }else{
     ClassAbilties[0].pic=SlashPicLocked;
     }
 
 //ablity 2    
     ClassAbilties[1].name="Double Slash";
     ClassAbilties[1].description="Slash The Enemy Twice";
     if(ClassAbilties[1].HaveAblity){
     ClassAbilties[1].pic=SlashPicUnlocked;
     }else{
     ClassAbilties[1].pic=SlashPicLocked;
     }
 }
 
 if(Classes.Lair){
 //ablity 2    
     PersonalityAbilties[0].name="Lie";
     PersonalityAbilties[0].description="Lie to enemy    ";
     if(PersonalityAbilties[0].HaveAblity){
     PersonalityAbilties[0].pic=SlashPicUnlocked;
     }else{
     PersonalityAbilties[0].pic=SlashPicLocked;
     }
 
 
 }
 }




Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by rasheedqw · Dec 26, 2014 at 04:38 PM

The Problem was line 25 of the second script ClassAbilties= new ablities2[5];. I dont Know why but it makes the array unreadable.I remove the line and it fix everything. If someoone can please tell me why this happens would love to know why thank you

Comment

People who like this

0 Show 0 · 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

Answer by Landern · Dec 26, 2014 at 02:03 PM

You need the class to serialize correctly, that means if it's directly(drag and drop style) attached to a GameObject, you should derive(extend) from MonoBehaviour, if it's not going to be directly attached to a GameObject, like you're doing in your example, ScriptableObject is the way to go:

 public class ablities2 extends ScriptableObject {
     public var name:String;
     public var pic:Texture2D;
     public var description:String;
     public var id:int;
     public var HaveAblity:boolean;
 }

You may also want to look into using List's instead of array's as you can manipulate them in code with ease.

Comment

People who like this

0 Show 2 · 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 rasheedqw · Dec 26, 2014 at 04:15 PM 0
Share

didnt know you could put class scripts on gameobject it only let me do that with c sharp scripts found the problem seems to be line 25 of the second script ClassAbilties= new ablities2[5]; dont really understand why but when i removed it everything worked fine. I use arrays because i understand them better. thanks for the info though

avatar image Landern · Dec 26, 2014 at 04:40 PM 0
Share

@rasheedqw, well, in the Awake function, when you do:

  ClassAbilties= new ablities2[5];

This will remove anything you did in the inspector as it reset the ClassAbilities variable to a capacity of 5 abilities items in the array.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Accesing custom class object from another script 1 Answer

How to serialize an array of classes 1 Answer

Storing questions/answers for a multiple choice game 1 Answer

array of objects 1 Answer

If there is only 1 instance of a class, should it be Static? - C# 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