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 Akisato · Jan 31, 2015 at 07:54 AM · arrayarray of gameobjectscopy

Copying Array from one script to another during runtime?

I have run into a strange issue working with arrays.

I have two scripts. Script A is attached to a PREFAB that is not in the scene until runtime. Script A simply has an array of gameobjects called playerDeck. I use the inspector and set the array to 30. I then populate it with PREFABS until all 30 slots are filled.

Script A:

 public GameObject[] playerDeck;

Moving onto script B. I have this script attached to a different gameobject that is there from the start and is NOT created on runtime.

Same deal, an array of prefabs set to 30 in the inspector but left all empty. I also have a gameobject set to have an instance of the player's prefab I fill the playerPrefab slot in the inspector by using the PREFAB named "player" This "player" has a script called playerScript.cs(Script A in this case)

I then call the line where I want to copy the deck, but nothing seems to copy over. The array for the second object doesn't copy anything over and is left blank.

Script B:

 public GameObject[] masterDeck;
 public GameObject playerPrefab;
 
 masterDeck = playerPrefab.GetComponent<playerScript>().playerDeck;

What am I doing wrong here? This is setting me back quite a bit. I suspect the issue is because I am using a prefab...is there any way around this?

EDIT: the object is instantiated. Script A is instantiated at runtime. I am using PUN(photon unity networking) to instantiated them. So I am not using the standard unity instantiation. could this be what is cause the problems?

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 Chris333 · Jan 31, 2015 at 08:12 AM

Hi,

you have to Instantiate the playerPrefab first and than you can get the playerDeck as you want.

http://docs.unity3d.com/ScriptReference/Object.Instantiate.html

E.g.:

 Instantiate(GameObject playerPrefab, new Vector3(0.0f,0.0f,0.0f), Quaternion.identity);
 masterDeck = playerPrefab.GetComponent<playerScript>().playerDeck;


Comment
Add comment · Show 5 · 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 Akisato · Jan 31, 2015 at 08:17 AM 0
Share

They are indeed instantiated. Forgot to mention that. Sorry!

avatar image Chris333 · Jan 31, 2015 at 08:20 AM 0
Share

Is the array with the prefabs you assign in the inspector which you want to copy also empty at runtime?(Script A - playerDeck)) Did you checked that.

avatar image Akisato · Jan 31, 2015 at 08:24 AM 0
Share

Yes I've checked that while the game is running. They are populated. Not empty at all. I am using PUN to instantiate them though...do you think that could be the problem?

avatar image Chris333 · Jan 31, 2015 at 08:27 AM 0
Share

Is that unity photon networking? I have no experience in that. You could check if your problem still exist without using photon.

avatar image Akisato · Jan 31, 2015 at 05:04 PM 0
Share

Yes this is using photon. I kinda need it since it's an online game I'm making. I will try it with objects that don't use photon and see if that works at all.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Copy Childen Of GameObjects From Array 1 To Array 2 1 Answer

Using an int to find the index of a GameObject array 1 Answer

How to copy part of an array 2 Answers

Accessing next Camera from array 1 Answer

Public Array of GameObjects 2 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