2015-02-24 62 views
1

在过去几个小时中,我遇到了一个令人不安的问题。 看来,我使用数组(int,float,byte等)进行的每个RPC调用都会导致整个引擎崩溃。 我做的如何重现一点点工作例子,我想知道,如果它肯定是一个错误,或者如果IM做一些非常错误的:RPC崩溃Unity

using UnityEngine; 
using System.Collections; 

public class NewBehaviourScript : MonoBehaviour { 

    // Use this for initialization 
    void Start() { 
     Network.InitializeServer(4, 25000, true); 
     networkView.RPC("test", RPCMode.All, new float[5]); 
    } 

    // Update is called once per frame 
    void Update() { 
    } 

    [RPC] 
    void test(float[] lol){ 
     Debug.Log("received "+lol); 
    } 
} 

在相机仅使用这个脚本用网络视图足以让事情崩溃。我做错什么了吗?? 在此先感谢!在Unity

+0

我整天都有同样的问题,我甚至格式化了我的电脑,它仍然崩溃。 最后我意识到我在过去一天升级了Unity,它应该是罪魁祸首。降级回4.6.1f后,效果很好! 然后我尝试找到有同样问题的人,显然你是唯一一个发布这个问题的人。 – tcboy88 2015-04-22 15:17:53

回答

2

正是在4.6.3和4.6.4的一个错误,当我尝试过在unity5的RPC它的工作发送的ByteArray。希望它有帮助

+0

确实现在工作。谢谢你提醒我! :d – markus 2015-04-09 09:47:31

0

使用RPC调用restricted to certain types of parameters

You can use the following variable types as parameters to RPCs:- int float string NetworkPlayer NetworkViewID Vector3 Quaternion

那么你可以做的反而是序列/数组转换为字符串,然后再返回到阵列上的另一侧。

+0

同意,但是当您尝试发送数据时它不受支持,我们收到此错误: “发送RPC失败,因为'teste'参数0(UnityEngine.GameObject)不受支持。”而不是完全崩溃。 – markus 2015-02-24 10:37:16

0

您需要将OnServerInitialized函数添加到您的类中。之后,您可以在此功能中使用networkView.RPC("test", RPCMode.All, new float[5]);

而且我也无法在您的班级中看到NetworkView实例。

public NetworkView networkView; 
void OnServerInitialized(){ 
    Debug.Log("Server initialized and ready"); 
    networkView.RPC("test", RPCMode.All, new float[5]); 
} 
+0

它没有改变。仍然崩溃。 – markus 2015-02-24 11:14:04

+0

你有没有networkView实例?也许你得到空。 – 2015-02-24 11:14:44

+0

是的。当我没有,或者我没有连接,Unity会抛出一个“无法发送RPC W/O网络视图”或类似的东西。 – markus 2015-02-24 11:17:08