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
0
Question by Yusaku · Jan 19, 2014 at 07:47 PM · gameobjectarraysclassesassignment

Need help with assigning game objects to variable

made an array of a custom class and i want to assign a prefab to class variable so assigning from another(inspector exposed) variable. relvent Code:

 public class ChunkData  {
     public string BiomeName            ="Forest";
     public GameObject landType        =null;
     public GameObject[] NatureTypes    =null;//list of nature placeables
     public GameObject[] ObjList     =null;//list if generated objects
     public Object[] LoadedList;    
     public float worldX                =0;//location in world in unity units
     public float worldZ                =0;//location in world in unity units
     public int objDensity            =100;    
 }
 
 
 
 public class LandGenerator3 : MonoBehaviour {
     public GameObject LandMesh         =null;//land object(for now)
 
 void Start () {
         ChunkList = new ChunkData[worldSizeX, worldSizeZ];
 
 void FillChunks(){
         for (int x=0; x < worldSizeX; x++) {
             for (int z=0; z < worldSizeZ; z++) {
                 ChunkList [x, z].landType         = LandMesh ;**<<where i get error**
                 ChunkList [x, z].NatureTypes     = NatureList;
                 ChunkList [x, z].objDensity     = objDensity;
                 ChunkList [x, z].worldX         = x * 50;
                 ChunkList [x, z].worldZ         = z * 50;
                 CreateChunk(ChunkList[x,z],x,z);
                 print ("Chunk Filled?");
             }
         }
     
     }
 
 
Comment
Add comment · Show 2
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 Yusaku · Jan 19, 2014 at 09:33 PM 0
Share

this is the error i get btw: NullReferenceException: Object reference not set to an instance of an object LandGenerator3.FillChunks () (at Assets/LandGenerator3.cs:38) LandGenerator3.Start () (at Assets/LandGenerator3.cs:20)

avatar image Yusaku · Jan 20, 2014 at 06:26 PM 0
Share

sorry maybe i wasnt clear: public GameObject Land$$anonymous$$esh =null; < is assigned prefeab in editor

ChunkList [x, z].landType = Land$$anonymous$$esh ; is where im having my problem this is in same script as Land$$anonymous$$esh.

Chunklist is an array of type ChunkData which is defined in a script solely as a Class type not attached to any game

2 Replies

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

Answer by Yusaku · Jan 20, 2014 at 07:30 PM

Figure it out( a way anyway) you have to "reserve memory" for your data from your class, at least arrays and the like. for example:

 void InitChunks(){
         for (int x=0; x < worldSizeX; x++) {
             for (int z=0; z < worldSizeZ; z++) {
                 ChunkList[x,z]                = new ChunkData();
                 ChunkList[x,z].landType     = new GameObject("land");
                 ChunkList[x,z].NatureTypes     = new GameObject[10];
                 ChunkList[x,z].ObjList        = new GameObject[objDensity];
                 ChunkList[x,z].LoadedList    = new Object[objDensity];
                 ChunkList[x,z].ObjLoc        = new Vector3[objDensity];
             }
         }
     }
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 getyour411 · Jan 19, 2014 at 07:49 PM

 public GameObject myPrefab;

Drag/Drop prefab into it in Editor, or assign GObj reference in another script to thisScript.myPrefab

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

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

18 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

Related Questions

How do I conditionally instantiate gameobject in a public class array? 0 Answers

Classes : extend MonoBehaviour issues 1 Answer

Component or Independent class 1 Answer

how to construct all arrays (classes) with default constructor (not possible) 2 Answers

Once again, adding GameObjects to an array 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