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 joeyaaaaa · Feb 03, 2013 at 09:42 AM · updateserverrpctransforms

Sending Update Transform Through RPC

i have three scripts, i am trying to update the position of sun on client based on where it is in the server, my sun is empty prefab with gametime script which moves its child(foundbyname) but the sun is what is instantiated so the light spawns moving, but when i leave and come back, it just starts over instead of moving and updating based on server, i need help solving the errors and updating the transform. i get two errors on server, none in client,

---error one

 > Couldn't send RPC function 'CheckSun'
 > 
 > UnityEngine.NetworkView:RPC(String,
 > RPCMode, Object[]) DaySpawn:CheckSun()
 > (at
 > Assets/scripts/server/DaySpawn.js:17)
 > DaySpawn:FixedUpdate() (at
 > Assets/scripts/server/DaySpawn.js:5)

---error two

 > nullreference NullReferenceException:
 > Object reference not set to an
 > instance of an object
 > Boo.Lang.Runtime.RuntimeServices.GetDispatcher
 > (System.Object target, System.String
 > cacheKeyName, System.Type[]
 > cacheKeyTypes,
 > Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory
 > factory)
 > Boo.Lang.Runtime.RuntimeServices.GetDispatcher
 > (System.Object target, System.Object[]
 > args, System.String cacheKeyName,
 > Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory
 > factory)
 > Boo.Lang.Runtime.RuntimeServices.SetProperty
 > (System.Object target, System.String
 > name, System.Object value)
 > ClientReceive.sendUpdateSunRotate
 > (System.String IDNumber, System.String
 > PrefabName, Vector3 Position) (at
 > Assets/scripts/ClientReceive.js:219)

heres day spawn

 > var PrefabName : String;
 > 
 > function FixedUpdate() {     CreateSun();
 >     CheckSun(); }
 > 
 > function CreateSun () {
 > 
 >          PrefabName = "Directional light";
 >     
 >                  }      function CheckSun() {      if (!GameObject.Find("PlayerDaySpawn")) {
 >         GameObject.Find("mObject").networkView.RPC("CheckSun",RPCMode.Others,gameObject.name,PrefabName,transform.position);
 >              }
 >     else if (GameObject.Find("PlayerDaySpawn")) {
 >         GameObject.Find("mObject").networkView.RPC("sendUpdateSunRotate",RPCMode.Others,gameObject.name,PrefabName,transform.position);
 >              }     }

here is SunClient

 > private var PrefabName : String;
 > 
 > 
 > function Start () {
 > 
 > }
 > 
 > function FixedUpdate () { if
 > (Vector3.Distance(transform.position,GameObject.Find("Player").transform.position)
 > < 10050) {         if
 > (!GameObject.Find("Player"+DaySpawn))
 > {             var newItem =
 > Instantiate(Resources.Load("worlditems/Weathers/Directional
 > light1",Transform),Vector3(0,0,0),Quaternion.Euler(Vector3.zero));
 >             newItem.name =
 > "Player"+gameObject.name;
 >             newItem.transform.parent =
 > GameObject.Find("Sun
 > Point").transform;
 >             newItem.transform.rotation =
 > GameObject.Find("Sun
 > Point").transform.rotation;
 >             GameObject.Find("mObject").networkView.RPC("sendUpdateSunRotate",RPCMode.Others,gameObject.name,PrefabName,transform.position);
 >         }     }     }

Here are two functions in client recieve

 > @RPC function
 > sendUpdateSunRotate(IDNumber :
 > String,PrefabName : String,Position :
 > Vector3){     newItem =
 > GameObject.Find(IDNumber);
 >     newItem.name = IDNumber;
 >     newItem.GetComponent("SunClient")
 > ``.PrefabName = PrefabName;
 >     newItem.transform.position =
 > GameObject.Find("DaySpawn").GetComponent("Directional
 > light").Rotation;     }
 > 
 > @RPC function CheckSun(IDNumber :
 > String,PrefabName : String,Rotation :
 > Vector3) { if
 > (!GameObject.Find(IDNumber)) { var
 > newItem =
 > Instantiate(Resources.Load("worlditems/Weathers/sunWeather",Transform),Vector3(0,-100,0),Quaternion.Euler(Vector3(0,0,0)));
 >     newItem.name = IDNumber;
 >     newItem.GetComponent("SunClient").PrefabName
 > = PrefabName;     newItem.transform.position =
 > Rotation; } }





Comment
Add comment · Show 3
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 Loius · Feb 03, 2013 at 11:29 AM 0
Share

What is ``, and please indicate the lines the errors are occuring on.

Use the 101-010 button to format your code. Just copy directly from your script file.

avatar image joeyaaaaa · Feb 03, 2013 at 11:44 AM 0
Share

i dont know what you mean, what is " ? but i recognize that i get that if i leave a bracket out at the end of my code, it returns an error saying expecting } but found " but i dont think thats happening here,

the null error is

  @RPC
 function sendUpdateSunRotate(IDNumber : String,PrefabName : String,Position : Vector3){
     newItem = GameObject.Find(IDNumber);
     newItem.name = IDNumber;
 
 
     newItem.GetComponent("SunClient").PrefabName = PrefabName;
          For this line^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
       
     newItem.transform.position = GameObject.Find("DaySpawn").GetComponent("Directional light").Rotation;
     }
 and it may take me a $$anonymous$$ute to produce the other checksun error for clarification as it isnt happening, at the moment anyways
avatar image joeyaaaaa · Feb 03, 2013 at 11:52 AM 0
Share

okay so the second error happens when i leave that scene or come back,

 function CheckSun() {
      if (!GameObject.Find("PlayerDaySpawn")) {
         GameObject.Find("mObject").networkView.RPC("CheckSun",RPC$$anonymous$$ode.Others,gameObject.name,PrefabName,transform.position);
     points to here ^^^^^^^^^^^^^^^^^^^^^^^^^^^    
     }
     else if (GameObject.Find("PlayerDaySpawn")) {
         GameObject.Find("mObject").networkView.RPC("sendUpdateSunRotate",RPC$$anonymous$$ode.Others,gameObject.name,PrefabName,transform.position);
         
     }
     }

im obviously probably makign a simple mistake but ive done all i can do" lol

1 Reply

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

Answer by Loius · Feb 03, 2013 at 12:59 PM

Whatever object is being found in sendUpdate does not have a SunClient component attached. You should use Debug.Log statements to track the status of your variables and make sure you're getting/sending the right information.

Side note: All those strings make it really easy for you to make mistakes which are incredibly hard to find. Using GetComponent(Type) is harder to get wrong, and storing references instead of using .Find all the time improves your performance and prevents you from accidentally finding the wrong object without noticing.

Comment
Add comment · Show 5 · 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 joeyaaaaa · Feb 03, 2013 at 01:06 PM 0
Share

thank you for your post, i suppose i must change the object that is being found,sun client gets created and is still instantiated seperatly from the other playerdayspawn,ill try to figure out how to change the components to get type and i dont know anything about storin refs, ill attempt some debugs, i am not very well at working with code that is non existance, i am only good at editing what is there, lol edit i see newItem.GetComponent("SunClient").PrefabName = PrefabName; when new item isnt the object with sunclient lol but i think this is only half the battle

avatar image joeyaaaaa · Feb 03, 2013 at 01:25 PM 0
Share

i changed that line to PlayerDaySpawn and it yields the same errors

avatar image Loius · Feb 03, 2013 at 02:39 PM 0
Share

newItem.GetComponent("") is returning null, which means that the item you got does not have the component you're asking for. Check your object's name, be sure there's nothing else with the same name anywhere, and be sure it has that component on it.

avatar image joeyaaaaa · Feb 03, 2013 at 02:50 PM 0
Share

okay,and thank you for your post, i think i need this component somewhere else, so i might end up changing that, but this still only is half the battle hehe maybe a more simple"system" might be necessary, just a rotating object that all clients see

edit, in the end will tracking the transform of the object also show its childrens transforms?

avatar image joeyaaaaa · Feb 03, 2013 at 03:53 PM 0
Share

after messing a bit ive made these changes but still have a few errors

 Sending RPC failed because 'sendUpdateSunRotate' parameter 1 was null
 UnityEngine.NetworkView:RPC(String, RPC$$anonymous$$ode, Object[])
 SunClient:FixedUpdate() (at Assets/Resources/worlditems/Weathers/SunClient.js:16)

 @RPC
     function CheckSun(IDNumber : String,PrefabName : String,Position : Vector3) {
     if (!GameObject.Find(IDNumber)) {
     var newItem = Instantiate(Resources.Load("worlditems/Weathers/sunWeather",Transform),Vector3(0,-100,0),Quaternion.Euler(Vector3(0,0,0)));
         newItem.name = IDNumber;
         Debug.Log("This is Check Sun     "+IDNumber);
         second errorVVVVVVNull reference
         newItem.GetComponent("PlayerDaySpawn").PrefabName = PrefabName;
         Debug.Log("This is Check Sun      "+PrefabName);
         newItem.transform.position = Position;
     }
     }
     @RPC
     function sendUpdateSunRotate(IDNumber : String,PrefabName : String,Position : Vector3){
         newItem = GameObject.Find(IDNumber);
         newItem.name = IDNumber;
         Debug.Log("This is send update"+IDNumber);
     
     first error VVVVVVVparameter 1 was null
         newItem.GetComponent("PlayerDaySpawn").PrefabName = PrefabName;
         Debug.Log("This is send update"+PrefabName);
         newItem.transform.position = GameObject.Find("DaySpawn").GetComponent("Directional light").Rotation;
         }

edits to dayspawn.js

   var PrefabName : String;
     
     function FixedUpdate() {
     
         CheckSun();
     }
     
     function CheckSun() {
         
         GameObject.Find("mObject").networkView.RPC("CheckSun",RPC$$anonymous$$ode.All,gameObject.name,PrefabName,transform.position);
     if (GameObject.Find("PlayerDaySpawn")) {
         GameObject.Find("mObject").networkView.RPC("sendUpdateSunRotate",RPC$$anonymous$$ode.All,gameObject.name,PrefabName,transform.position);
             
         }
         }

edits to sunclient private var PrefabName : String;

 function Start () {
 
 }
 
 function FixedUpdate () {
 if (Vector3.Distance(transform.position,GameObject.Find("Player").transform.position) < 10050) {
         if (!GameObject.Find("Player"+DaySpawn)) {
         Debug.Log("Spawning from sunclient fixed update");
             var newItem = Instantiate(Resources.Load("worlditems/Weathers/Directional light1",Transform),Vector3(0,0,0),Quaternion.Euler(Vector3.zero));
             newItem.name = "Player"+DaySpawn;
             newItem.transform.parent = GameObject.Find("Sun Point").transform;
             newItem.transform.rotation = GameObject.Find("Sun Point").transform.rotation;
             GameObject.Find("mObject").networkView.RPC("sendUpdateSunRotate",RPC$$anonymous$$ode.All,gameObject.name,PrefabName,transform.position);
              
     }
     }
     }    
     im still attempting to debug so please bare with me

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

10 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

Related Questions

A node in a childnode? 1 Answer

Multiplayer Help? 0 Answers

Is server the sender of RPC? 0 Answers

RPC to server from client 1 Answer

Wireless updates through internet? 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