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 jorgon · Nov 30, 2011 at 12:16 PM · instantiatenetworkcolor

Combination of Instance and random in a network game

Hi mates!.

Why in server and client the instances appear with different colors? . What I'm instantiating are a random ballons with different colors. The instant and position and the falling over the ground are well synchronized.

 function Update () 
 {    
   if(Network.isServer)
     {
     var viewID2 = Network.AllocateViewID();
     networkView.RPC("SpawnBox",RPCMode.All,viewID2,transform.position); 
 
     @RPC
     function SpawnBox (viewID2 : NetworkViewID, location : Vector3) 
     {
     // Instantate the prefab locally
     var clone : GameObject;
     clone = Instantiate(array_of_balloons[Random.Range(0,array_de_globos.Length)], transform.position+Vector3 (Random.Range(0, gridX),0, Random.Range(0, gridY))*spacing , Quaternion.identity);
                             
        var nView : NetworkView;
         clone.AddComponent(NetworkView);
         nView = clone.GetComponent(NetworkView);
         nView.viewID = viewID2;
      }
 }   

}

Thank you very much.

Please, help me.

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

Answer by syclamoth · Nov 30, 2011 at 12:33 PM

What exactly is the problem here? I mean, obviously the boxes won't instantiate in the correct positions because the Random gets called on the clients upon instantiation, but you tell me that's working- what's the issue then? I would do it something like this-

 @RPC
 function SetColour(float r, float g, float b, float a)
 {
     var recievedColor : Color = new Color(r, g, b, a);
     // from here, do what you like
 }

 Then, when they get instantiated, after the networkView gets set-

 if(networkView.isMine)
 {
     networkView.RPC("SetColour", RPCMode.All, Random.value, Random.value, Random.value, Random.value);
 }

Otherwise, you shouldn't be calling random things on clients if you expect them to act sensibly. You should do the random stuff on the server (the one that's instigating the instantiation), and send it with the position and rotation info.

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 jorgon · Dec 01, 2011 at 07:35 AM 0
Share

HEY!. Thank you!!. I think this is the idea. The idea would be to create a random number and choose one of the three elements of my set of prefabs from which I choose the instance via the random command, and then build a function like yours but sending the client the same RANDO$$anonymous$$ INDEX for both: client and server...IT $$anonymous$$UST WOR$$anonymous$$!!. Let me try this and I will tell you!! . IT $$anonymous$$UST WOR$$anonymous$$, IT $$anonymous$$UST WOR$$anonymous$$... ;-) . I'm happy!.

avatar image syclamoth · Dec 01, 2011 at 09:22 PM 0
Share

Yes, that would work! It's actually more efficient than sending 3 floats over the network, too.

avatar image
0

Answer by jorgon · Dec 02, 2011 at 01:36 PM

I've solved the problem generating a random number which I use as an index to select one of the three elements of my array of ballons. I generate the number out of the " if(Network.isServer)" and then I send the index

 if(Network.isServer)
  {
  networkView.RPC("SpawnBox",RPCMode.All,viewID2,transform.position,index); 

and inside of my RPC function:

 clone = Instantiate(array_de_globos[num], transform.position+Vector3 (Random.Range(0, gridX),0, Random.Range(0, gridY))*spacing , Quaternion.identity);


The problem I've got now is that I receive two messages continuosly (due to the update loop):

View ID AllocatedID: 6316 not found during lookup. Strange behaviour may occur. Couldn't perform remote Network.Destroy because the network view 'AllocatedID: 6316' could not be located.

The problem now is that after the right instantiation the destruction is made in another script...I don't know if this is related to the error messages which don't disturb for the execution.

Thank you in adavance.

Comment
Add comment · Show 1 · 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 syclamoth · Dec 02, 2011 at 03:01 PM 0
Share

Please, open a new question for this since it's a different problem only tangentally related.

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

How to instantiate a prefab and change its color? 5 Answers

How can I instantiate an Orthello prototype with the Network class? 1 Answer

IgnoreCollision on a Network Instantiated Object 2 Answers

Network.Instantiate fired from client AND server 1 Answer

Network.Instantiate spawns multiple objects 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