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
1
Question by Z2CSharp · Jan 16, 2015 at 11:54 PM · networkinggetcomponentvariablesrpcnetwork.instantiate

Changing a variable in another script over the network

Hello,

I am trying to find out how to find out how to change a variable in an object I just instantiated over the network using an RPC call. However, the variable damage and gameObject name only change locally and not over the network. This object and the object I'm trying to reach have a networkView. Any help is appreciated.

 [RPC]
     public void DealMapWideDamage(float amount)
     {
         mapWideAOEClone = Network.Instantiate(Resources.Load("MapWideAOE"), new Vector3(0,0,0),Quaternion.identity,0) as GameObject;
         //Need to find out a way to give MapWideAOE the variable damage
         mapWideAOEClone.name = "Damage";
         Damage_Script damage_Script = mapWideAOEClone.GetComponent<Damage_Script>(); //Get damage script and deal some damage
         damage_Script.damage = amount; //etc.
     }

 void Update() //Using update to show how I'm declaring the rpc call
 {
      networkView.RPC("DealMapWideDamage",RPCMode.All,damage);
 }




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

1 Reply

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

Answer by jpthek9 · Jan 17, 2015 at 12:04 AM

There aren't any errors in the code as far as I can tell. Note that when you use networkView.RPC, you're calling the RPC on that networkView on all clients. So if you want to tell the enemy you hit to take damage, you would call that enemy's networkView instead of your own.

Are there any errors popping up or are debug.logs simply not showing up?

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 Z2CSharp · Jan 17, 2015 at 03:03 PM 0
Share

Sorry about that, I updated the code to show how I'm doing the RPC call.

avatar image Z2CSharp · Jan 19, 2015 at 08:40 PM 0
Share

No errors appear, it just seems that I can't access and modify these variables over the network.

avatar image jpthek9 · Jan 19, 2015 at 09:25 PM 0
Share

I'm sorry but there's nothing wrong with what you're showing.

avatar image Z2CSharp · Jan 19, 2015 at 10:04 PM 0
Share

Ok thank you for the help, I'll see if there is an error on my part Anywhere in my scripts.

avatar image Z2CSharp · Jan 21, 2015 at 02:20 AM 0
Share

jpthek9 is correct. After reviewing the output logs it does print the information I want it to. The name of the object changes on all, but as for getting the variable over the network... make it simpler on yourself by not getting the component but by using another method as from my experience with it, it could cause some trouble.

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

26 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Running only one script across clients and server 0 Answers

How to pass a variable to a late-joining player without syncvars? / What function gets called on a new player connect? 1 Answer

How do I GetComponent from a NetworkView? 0 Answers

RPCs and instantiations being dropped/appearing out of order 1 Answer

Problem storing GameObject reference in script - PUN 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