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 Azial · Mar 29, 2013 at 02:31 PM · networknetworkviewpass

Pass value over network without RPC-call?

This seems such a simple problem but somehow I don't get it:

I want to instantiate a gameobject in network and pass a value to the new created object that uses this value in it's Start() function and then delete it's networkview-component because it's not needed anymore. Network.Instantiate works fine, even the value gets passed before Start() on the client, but not for the other players. Note that in my case I can't use RPC-calls on the script that the object instantiates.

So I put the script in editor as observed for the networkview component, but it doesn't helped. I don't even get something with...

 function OnSerializeNetworkView(stream : BitStream, info : NetworkMessageInfo) {
     if (stream.isReading) {
         print("onserialize: read");
     }
     if (stream.isWriting) {
         print("onserialize: writing");
     }
     print("onserialize");
 }


...attched in the script that is on the instantiated object. Nothing is printed when I instantiate the objects.

How does OnSerializeNetworkView work? Probably I use it wrong, but the docs are just so superficial sometimes :( Even if I don't delete the networkview-component, it throws nothing!

Another strange thing for me is that I earlier forgot to attach the networkview component to the object I want to instantiate but it instantiated correctly (position and rotation) for the other players oO why? Is it just for synch when objects live long?

Should I make a RPC-call at Start() in the script from the instantiated object to short synch the value from the client to all the other players or is there a better way for this problem?

Comment
Add comment · Show 2
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 whydoidoit · Mar 29, 2013 at 02:33 PM 0
Share

Right well OnSerializeNetworkView is for sync after creation - as your NetworkView is gone not much will be happening.

The answer has to be RPC - there isn't another way. Build you own version of Network.Instantiate perhaps (that's what I do) with an scene component acting as the manager - then you can pass whatever you like to it.

avatar image Azial · Mar 29, 2013 at 03:40 PM 0
Share

Yeah, I solved the problem with RPC now.

$$anonymous$$issile-launcherscript from one of the players:

 public class $$anonymous$$issileLauncher extends Cast{
     var missile : $$anonymous$$issile;
     var offsetVector : Vector3 = Vector3(0, 0.2, 1.2);
     
     function UseCast() {
         var new$$anonymous$$issile : $$anonymous$$issile = Network.Instantiate(missile, transform.position + transform.TransformDirection(offsetVector), transform.rotation, 0);
         new$$anonymous$$issile.networkView.RPC("SetProjectileForce", RPC$$anonymous$$ode.AllBuffered, new$$anonymous$$issile.projectileForce + rigidbody.velocity.magnitude);
     }
 }


And here's the missiles script:

 var projectileForce : float = 30;
 var explosion : Transform;
 var effectForce : float = 100;
 var explodeAfterSek : float = 3;
 
 WaitAndExplode();
 
 function WaitAndExplode() {
     yield WaitForSeconds(explodeAfterSek);
     Destroy$$anonymous$$e();
 }
 
 @RPC
 function SetProjectileForce (realProjectileForce : float) {
     rigidbody.velocity = transform.forward * realProjectileForce;
 }
 
 function OnTriggerEnter(other : Collider) {
     if (other.rigidbody) {
         other.rigidbody.AddForceAtPosition(transform.forward * effectForce + Vector3(0, effectForce, 0), transform.position, Force$$anonymous$$ode.Impulse);
         Destroy$$anonymous$$e();
     }
 }
 
 function Destroy$$anonymous$$e() {
     Instantiate(explosion, transform.position, transform.rotation);
     Destroy(gameObject);
 }


A networkview-component must be attched to the missile, but State Synch can be "Off" and observed "None", so I wouldn't have too much traffic.

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

11 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

Related Questions

Why is there an issue with Network recognition when networkView.isMine is called from within Update function ? 0 Answers

How to update a script to a network script 1 Answer

Network.Instantiate dont instantiate object 0 Answers

Should you disable NetworkView when offline 1 Answer

Can not make RPC calls during Start() 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