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 /
  • Help Room /
This question was closed Jul 03, 2016 at 04:45 PM by DocLamb for the following reason:

The question is answered, right answer was accepted. I was able to figure it out on my own it was an issue solely with my code, though I'm not sure why as of yet.

avatar image
0
Question by DocLamb · Jul 03, 2016 at 04:24 AM · c#instantiatearray

Checking if an instance of a Script saved in 3d array is null

I apologize in advance if there is already and answer out there for this question but I couldn't come up with one.

I am procedurally generating a map and randomly instantiating game objects on certain locations and saving those objects scripts that I attached to all the objects into a 3D array that is a respective index of the entire map.

I am then trying to upon clicking on a point on the map check if there are any objects saved in the array for that location in 3D space.

The array is created in my game manager script like so.

 int worldX = 16;
 int worldY = 16;
 int worldZ = 16;
 public SceneObject[,,] SceneGo;
 void Start(){
 SceneGo = new SceneObject[worldX,worldY,worldZ];
 }

Then in another script a random integer is called and based of that an object will be placed or more often no object will be created like so.

         int rand = (int)Random.Range(0, world.SceneryObject.Length + world.SceneryFactor*10 );
         if (rand < world.SceneryObject.Length) {
             Vector3 pos = new Vector3(x+chunkX, y+chunkY+0.75f, z+chunkZ);
             world.SceneGo[x + chunkX, y + chunkY, z + chunkZ] = (Instantiate(world.SceneryObject[rand],pos,Quaternion.identity) as GameObject).GetComponent<SceneObject>() ;
             world.SceneGo[x + chunkX, y + chunkY, z + chunkZ].x = x+chunkX;
             world.SceneGo[x + chunkX, y + chunkY, z + chunkZ].y = y+chunkY;
             world.SceneGo[x + chunkX, y + chunkY, z + chunkZ].z = z+chunkZ;
             world.SceneGo[x + chunkX, y + chunkY, z + chunkZ].index = world.sceneObjs;
             world.sceneObjs++;

Then in another script on click a call will be made to see if an index of that array is null or not.

     void CheckForObstruction(Vector3 position) {
         int x = (int)position.x;
         int y = (int)position.y;
         int z = (int)position.z;
         if(world.SceneGo[x,y,z]!=null)Debug.Log("Obstructing object found");
     }

Currently I am using a much larger map than 16x16x16 so I don't know if the size of the array is the issue, but if there is a fix out there that doesn't require an entire rethinking of the way I am doing this I would much appreciate it.

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

  • Sort: 
avatar image
0
Best Answer

Answer by DocLamb · Jul 03, 2016 at 04:44 PM

I doubt that this will be able to help anyone that is running into the same issue, but through messing around with my code and several steps of debugging i found that evidently the objects were being indexed to the (y-1) spot rather than the y spot, so in my check I simply made the adjustment and the script seems to be working now.

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

Follow this Question

Answers Answers and Comments

182 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 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

Instantiating prefabs from an array of GameObjects 3 Answers

IndexOutOfRangeException error when getting transform of array object 0 Answers

Destroy a Prefab from an Array? (C#) 2 Answers

How to instantiate bullets in multiple transforms 1 Answer

How can i Instantiate gameobject in array 0 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