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 thetemplar · Dec 05, 2014 at 12:34 AM · multiplayergameobject.findgameobject.findgameobject

Find a GameObject without a reference

Hello everyone,

I am building a RTS-Lockstep implementation right now and have a question: I successfully instantiate gameObjects on all clients, but now I want to destroy one of them. How do I identify a gameObject without a reference (because every client has another ref.)? First thing I thought of is giving the gameObject a "public int ID" via script, but then I would have to iterate over all gameobjects to find the chosen one.`

There must be a better way....

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
0
Best Answer

Answer by Kiwasi · Dec 05, 2014 at 02:01 AM

Short Answer

Maintain all of your GameObjects in a List or Dictionary of some sort. Then call them by index, which can be your unique ID.

Long Answer

I do think you are getting lockstep wrong. Lockstep networking relies entirely on each client performing the simulation identically, based on a set of orders from all of the other clients. So the only data you should ever be passing through your network is the orders. When all orders are received each client will run the next step of the simulation.

So to lockstep an RTS you should never need to instantiate or destroy an object over the network. Rather you send the orders across all clients, and each client instantiates and destroys its own objects, based on a local calculation of the simulation.

Comment
Add comment · Show 3 · 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 thetemplar · Dec 05, 2014 at 03:24 AM 0
Share

The List idea is interesting.

And regarding your long answer: I do get it right, everything is as you described it. But if the player for example "sells" a building, the GameObject needs to be destroyed (or after a unit dies etc.).

Its less about the destroying itself but on how to address objects (for example a player has multiple towers and upgrades one, how do I guarantee that its on all clients the same tower without massive overhead)

avatar image Kiwasi · Dec 05, 2014 at 03:29 AM 0
Share

A dictionary will probably be the better idea then a list. Dictionaries are typically faster for adding and removing. Give every GameObject a unique ID when creating. Add it to the dictionary with this ID.

Then when you send orders across the network you can tag them with the ID of the GameObject they effect.

avatar image thetemplar · Dec 05, 2014 at 03:33 AM 1
Share

That sounds wonderful, I think I am doing that.

Dict<int, GameObject> for the ID and the reference to the object. Due to the implementation of lockstep every ID represents the same object on every client.

Thanks alot!

avatar image
0

Answer by jpthek9 · Dec 05, 2014 at 01:42 AM

GameObject LeObject = Network.Instantiate("Prefab"); int ID = NetworkView.ViewID;

Then you send that through and RPC or somefin...

GameObject LeObject = NetworkView.Find(ID).gameObject;

As side note: An RTS is a HUUUGEEEE pain to get going. I tell you this from experience. I recommend you try getting something like an FPS going or a game like Dungeon Crawlers before becoming this ambitious. Don't lose hope though. Just learn the basics so you know what you're doing. That way, you can code your game efficiently from the ground up and won't have to redo it after realizing a fatal error.

Comment
Add comment · Show 2 · 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 thetemplar · Dec 05, 2014 at 03:20 AM 0
Share

Its running fairly well so far ;-) And its not an "Network." instantiation, but two separate local GameObject.Instantiate ones, so there is no NetViewID.

avatar image jpthek9 · Dec 06, 2014 at 02:58 AM 0
Share

Ah, sorry. Glad you got through it, mate.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Get list of gameObjects and change booleans within them 2 Answers

OnDeserialize is not being called on by client. 0 Answers

Scene objects on multiplayer networking 1 Answer

How to make a camera work in this circumstance. 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