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
1
Question by MrAwesome343 · Jun 11, 2017 at 08:34 PM · arrayinspectorclassrpg

Public Array with a class not showing in Inspcetor

I have a class ItemClass and I'm trying to create a public ItemClass[] but I can't see anything in the inspector. Is there something missing? Here is the ItemClass followed by the script with the array:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ItemClass {
 
     private string itemName;
     private string itemDesc;
 
     private int cost;
     private int dungeonUnlock;
 
     private int attackInc;
     private int defenseInc;
     private int vitInc;
 
     private int healingAmount;
     private string loadScene;
 
     public enum ItemType
     {
         Accessory,
         Armor,
         Weapon,
         Potion,
         Support
     }
     private ItemType itemTypes;
 
 
     public string ItemName { get; set; }
     public string ItemDesc { get; set; }
 
     public int Cost { get; set; }
     public int DungeonUnlock { get; set; }
 
     public int AttackInc { get; set; }
     public int DefenseInc { get; set; }
     public int VitInce { get; set; }
 
     public int HealingAmount { get; set; }
     public string LoadScene { get; set; }
 
 
     public ItemType ItemTypes { get; set; }
 
 }

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [System.Serializable]
 public class ShopContents : MonoBehaviour {
 
     public ItemClass[] allItems;
     public GameObject[] gameObjects;
     public List<ItemClass> availableItems;
 
     void Start()
     {
         availableItems = new List<ItemClass>();
 
         DungeonCheck();
     }
 
     void DungeonCheck()
     {
         availableItems.Clear();
         foreach (ItemClass item in allItems)
         {
             if (PlayerStatManager.dungeonsBeaten >= item.DungeonUnlock)
             {
                 availableItems.Add(item);
             }
         }
     }
 
 }


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

1 Reply

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

Answer by PizzaPie · Jun 11, 2017 at 08:57 PM

 [System.Serializable]
 public class ItemClass {...

And change the fields to public OR mark them with [SerializeField] to to see them on inspector (properties are not visible/seriazable on inspector)

As for the shopContents class you don't need to mark it as serializable.

Comment
Add comment · 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 MrAwesome343 · Jun 11, 2017 at 11:27 PM 0
Share

Thank you, that made it appear in the inspector, but I can't add to the elements regardless of array size for my ItemClass[]

avatar image PizzaPie MrAwesome343 · Jun 12, 2017 at 12:40 PM 0
Share

Not sure what you mean, anyway if you didn't mark the fields with public ins$$anonymous$$d of private OR mark them with [SerializeField] they won't be visible in inspector. To add more elements to the array just change the size of the array on the inspector.

 public class ItemClass {
  
      [SerializeField]
      private string itemName;
      [SerializeField]
      private string itemDesc;
      [SerializeField]
      private int cost;
      [SerializeField]
      private int dungeonUnlock;
 //...

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

78 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

Related Questions

View script variables within an array of scripts in Inspector 1 Answer

[SOLVED]How to use attributes from array of custom class instances? 1 Answer

How to serialize an array of classes 1 Answer

Array of abstract class in inspector 2 Answers

Setting up an array of Items 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