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 sgmongo · Aug 06, 2012 at 09:04 PM · networkvariable

How do I make variables update on a network script?

Hello,

I've not been able to find this in a search, and the networking tutorial I downloaded from unity was not documented very well compared to their other tutorials. I was a little downtrodden.

I'm trying to send data from a object on server to the client. This object I'm calling the DTH has networkviews attached to both the object and the script. Problem is, everytime the server changes a variable on the DTH, and the client requests that variable, it returns only its original value of "not what I expect". When that same variable is viewed from the server, it changes properly, but when viewed from client, it does not.

Script:

pragma strict

var teststring : String = "not what I expect";

function incstring ( inc : String ) { teststring = inc; }

function checkstring ( requestor : GameObject ) { requestor.SendMessage("updatestring", teststring, SendMessageOptions.DontRequireReceiver); }

So the question is, how do I make it function as I intend?

If this is not possible, what do you suggest as an alternate way to send and recieve updated data.

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 williampigmeu · Aug 06, 2012 at 09:55 PM 0
Share

Try with: requestor.Send$$anonymous$$essage(teststring, Send$$anonymous$$essageOptions.DontRequireReceiver);

This will send the "teststring" value.

avatar image ScroodgeM · Aug 06, 2012 at 10:04 PM 0
Share

Send$$anonymous$$essage is not network method. it will not send anything via network.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ScroodgeM · Aug 06, 2012 at 09:15 PM

http://docs.unity3d.com/Documentation/ScriptReference/NetworkView.RPC.html

feedback if need explain

Comment
Add comment · Show 7 · 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 sgmongo · Aug 06, 2012 at 09:37 PM 0
Share

I'm completely confuzzled by the documentation. I tried adding @RPC in front of both methods. No change. I get the feeling I need a decent tutorial to break in down into consumable pieces for me. Sorry that I couldn't get it the first try.

avatar image ScroodgeM · Aug 06, 2012 at 09:41 PM 1
Share

that can't be solved only adding '@RPC' 8)

  • be sure object that should receive data have NetworkView component

  • write a receiving method (see link for example) for client

  • write a sending method (see link for example) for server

    networkView.RPC(...);
  • run server and client

  • connect them

  • now, calling the sending method on server should be received by client

avatar image sgmongo · Aug 06, 2012 at 10:05 PM 0
Share

Like this?

'#pragma strict

var teststring : String;

function incstring ( inc : String ) { teststring = inc; }

function checkstring ( requestor : GameObject ) { networkView.RPC("checkstringrpc", RPC$$anonymous$$ode.AllBuffered, requestor); }

@RPC function checkstringrpc (requestor : GameObject ) { requestor.Send$$anonymous$$essage("updatestring", teststring, Send$$anonymous$$essageOptions.DontRequireReceiver); }

Sorry to ask but the Unity master server isn't allowing me to connect and test.

avatar image ScroodgeM · Aug 06, 2012 at 10:08 PM 1
Share

i'm not strong in JS, but looks correct...

BUT... Valid RPC parameters are int, float, string, NetworkPlayer, NetworkViewID, Vector3 and Quaternion.

http://docs.unity3d.com/Documentation/ScriptReference/NetworkView.RPC.html

you can't send a whole gameobject via network 8) send a link to it as NetworkViewID if this is network object.

avatar image ScroodgeM · Aug 06, 2012 at 10:21 PM 1
Share

realize RPC exactly from example to understand how it works...

Show more comments

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Updating variable on another script. It is not working. 2 Answers

Transfer values from one script to another 1 Answer

how can I send file via network ? 0 Answers

How to make two scripts share same variable? 1 Answer

Unity thinks my animation is not attached, but it is. 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