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 galshal · Apr 07, 2015 at 08:35 AM · multiplayerphotoninstantiated

need to capture all the object instantiated to the multiplayer

Hi guys, Im creating a multiplayer game, in it Im instatinating a ship using

 photonNetwork.instantiate();

the instantiate is working fine

what i need to do next is to find all the gameobjects created in this way and to enter it to array or a list

i tried to use

 GameObject.Find(ship);

or even

 GameObject.findGameObjectsWithTag(ships);

both returning null

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by winsjansen · Apr 07, 2015 at 09:13 AM

I don't have any experience with photonNetwork api, but I'm pretty sure that when you instantiate an object it will always be given a unique name in some way, for example "ship1" or "ship clone v2" etc, therefore you can't just search for "ship" as it doesn't exists (try check the inspector in the editor on runtime to see the name of the objects)

I suggest you try to cast the instantiation as a transform, and set it's parent to another static gameobject so that you can just iterate through it, to create a list of all it's childs like this;

 foreach (Transform child in theObjectYouAddEveryShipTo)
 {
     List<GameObject> listOfThemAll = new List<GameObject>();
     listOfThemAll.Add(child);
 }

I'm not sure where you would want to cast it though, as I've not used photonNetwork before, but if you need any more help please let me know, and we'll try to sort it for you.

Comment
Add comment · Show 6 · 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 galshal · Apr 07, 2015 at 09:31 AM 0
Share

thanks,

i tried to change the name of the find to ship(clone) same as the inspector. still i get null.

i knew that i will probably have a problem with the name so i set a tag to gameObject

but the result is the same

avatar image winsjansen · Apr 07, 2015 at 09:41 AM 0
Share

Hm, I don't know what you are doing wrong.

Can you try instantiating 5 objects and tell me the name of each one of them, also check what tag each of them carry?

avatar image galshal · Apr 07, 2015 at 10:41 AM 0
Share

every one of the objects is called Ship(Clone) the tag name is Ships I entered the tag this way

 gameObject.tag = "Ships";
avatar image Pharaoh_ · Apr 07, 2015 at 10:46 AM 0
Share

I don't get why you don't use a game object variable to instantiate your prefab and then add it directly to a List. Then, you can browse the elements of the list by using a for loop with i < list.Count - 1. This way you have instant access to every ship in your scene. The list should be List .

avatar image winsjansen · Apr 07, 2015 at 11:19 AM 0
Share

Problem is you can't just cast the method from the API as far as I know, since it doesn't return anything. But as I already mention to him you should try casting it and see;

 GameObject name = (GameObject)photonNetwork.instantiate();
Show more comments
avatar image
0

Answer by wesleywh · Apr 07, 2015 at 07:18 PM

If all you want to do is add it to some array list on a object just make a script that executes when the object is instantiated. On that script have it access some public variable on another object and have it push it onto its array. That's the easiest thing I can think of doing.

As it was mentioned before you can't search by names because they are going to change. You will have to search by tags by you typed it wrong(according to what you posted).

 GameObject myObject[] = GameObject.FindGameObjectsWithTag("Some Tag");//idk if i typed the array part right so just double check this.

You typed it with a lower case find. However, you will have to make sure not to add it twice thats why just having a OnStart() script would be the easiest thing to do.

Just put that OnStart script onto the objects prefab.

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

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

Photon - How to name a player? 0 Answers

Photon : Multiplayer car race game Camera Set 0 Answers

Photon Network Muzzleflash 0 Answers

Photon Unity multiplayer player name issue (worldtoscreenpoint?) 0 Answers

Photon - How can I get a list of ALL players in EVERY room? 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