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 Griffo · Apr 19, 2014 at 06:23 PM · arrayarraysstack

Copy Array to a Stack

Hi,

Is there a simple way to copy an array to a stack at Start, so when I pop one from the stack I do not end up with a (Clone)

I know "CopyTo" Copies the Stack to an existing one-dimensional Array and "ToArray" Copies the Stack to a new array.

But I want to the the other way, in .js

Thanks.

Comment
Add comment · Show 4
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 robertbu · Apr 19, 2014 at 06:32 PM 0
Share

Can't you just pass the array to the Stack constructor? Or are you trying to merge in the array?

avatar image Griffo · Apr 19, 2014 at 07:05 PM 0
Share

I thought this would do it

 #pragma strict
 
 import System.Collections.Generic;
 
 var objectStack : Stack.<Transform> = new Stack.<Transform>();
 var objectArray : GameObject[];
 
 private var poolSize : int;
 
 function Awake(){
 
     poolSize = objectArray.length;
     _loadPool();
 }
 
 function _loadPool(){
 
     for (var c : int = 0; c < poolSize; ++c){
         objectStack.Push(objectArray[c].transform);
         objectArray[c].SetActive(false);
     }
 }

But when I pop one out it does not show.

avatar image robertbu · Apr 19, 2014 at 07:13 PM 0
Share

You code looks fine. What happens when you put some Debug.Log() statements in the code? Is the size of objectStack the same as objectArray at the end? If you do a Peek() the stack each time through the loop, does the values in objectArray[c] and the value on the top of the stack match? If you dump the positions of both inside _loadPool after the for() loop, what do you see?

avatar image Griffo · Apr 19, 2014 at 08:10 PM 0
Share

robertbu, Sorry for wasting your time, I've been looking in the wrong place, the problem is in a script on the GameObject, that was stopping the GameObject showing when I'd popped it out of the stack …. O well you live and learn … Thanks for the input, appreciated.

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

Random an Array to push to another Array 0 Answers

Making objects follow each other in a line, and objects ignoring minimum follow distance. 2 Answers

How to merge an arrays into arrays inside an array? 3 Answers

adding classes to arrays 2 Answers

Array of variable-length arrays (JS) 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