- Home /
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; } }
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.
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
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
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.
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
i changed that line to PlayerDaySpawn and it yields the same errors
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.
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?
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
Follow this Question
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