Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Dracolyte · Apr 03, 2021 at 05:20 PM · arraysclassconstructor

How do i edit a constructor array in the inspector?

Im kinda new to coding and I like making things myself. But I dont know how to edit the properties from a constructor in an array in the inspector. I can drag and drop a class object but not edit the properties. For example: In my NPC constructor is a id of type int. I basically want to edit the id property in the inspector for one of the NPC constuctors in the array. I can only drag and drop a NPC class which i dont want to do.

My Spawner:

 public class LoadNPCAndObstacles : MonoBehaviour
 {
     public Transform[] ObstacleSpawns;
     public Transform[] NPCSpawns;
     
     [SerializeField]
     public NPC[] Npcs;
     
     void Start()
     {
         Npcs  = new NPC[NPCSpawns.Length];
     }
 
     
     void Update()
     {
         
     }
 }

My Constructor:

 public class NPC : Obstacle
 {
     public bool HasPath { get; set; }
     public GameObject Path { get; set; }
     
 
     public NPC(float hp, int id, Vector3 position, Quaternion rotation,GameObject prefab, bool hasPath, GameObject path) : base(hp, id, position, rotation, prefab)
     {
         HP = hp;
         ID = id;
         Position = position;
         Rotation = rotation;
         HasPath = hasPath;
         Path = path;
         Prefab = prefab;
     }
 
     public void CreateNPC()
     {
         Instantiate(this.Prefab, this.Position, this.Rotation);
     }
 }






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
0

Answer by Llama_w_2Ls · Apr 03, 2021 at 05:28 PM

Have you added the attribute System.Serializable at the top of your script? It should look like this:

 [System.Serializable] 
 public class NPC : Obstacle
  {
      public bool HasPath { get; set; }
      public GameObject Path { get; set; }
      
  
      public NPC(float hp, int id, Vector3 position, Quaternion rotation,GameObject prefab, bool hasPath, GameObject path) : base(hp, id, position, rotation, prefab)
      {
          HP = hp;
          ID = id;
          Position = position;
          Rotation = rotation;
          HasPath = hasPath;
          Path = path;
          Prefab = prefab;
      }
  
      public void CreateNPC()
      {
          Instantiate(this.Prefab, this.Position, this.Rotation);
      }
  }
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 Dracolyte · Apr 04, 2021 at 05:29 AM 0
Share

Yea, still i can only drag in a class and not change the properties

avatar image Llama_w_2Ls Dracolyte · Apr 04, 2021 at 09:15 AM 0
Share

Is there a need to make them properties instead of fields? You aren't using the get; set; accessors any differently, so you might as well change public bool HasPath { get; set; } to just public bool HasPath; and it should show up in the inspector.

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

115 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

Related Questions

How to add GameObject to List using a constructor method 1 Answer

how can I make a box with flat cubes(which I want to call a 'tile')? and have each tile detect collision? 0 Answers

Not a member of Object..Can't get class.name from array 1 Answer

Can i set class vars automatically when calling class constructor with attributes? 0 Answers

Class transform "null" keyword error. 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