- Home /
StarTrooper Networking Tutorial Script: Type Not Valid
I am doing the Multiplayer Tutorial, and am about 1/3 of the way down, having downloaded the StarTrooper scene. This has you create a C# script called NetworkRigidBody.cs, containing the NetworkRigidBody class, and apply it to your SpaceCraft prefab. To this you also attach another small script named RigidAssign.js containing the following code:
function OnNetworkInstantiate(msg : NetworkMessageInfo){
if (networkView.isMine){
var _NetworkRigidbody:NetworkRigidbody=GetComponent("NetworkRigidbody");
_NetworkRigidbody.enabled = false;
}else{
name+="Remote";
var _NetworkRigidbody2:NetworkRigidbody=GetComponent("NetworkRigidbody");
_NetworkRigidbody2.enabled = true;
}
}
This throws the following errors in Unity's console:
Assets/Plugins/RigidAssign.js(3,39): BCE0018: The name 'NetworkRigidbody' does not denote a valid type ('not found'). Did you mean 'UnityEngine.NetworkReachability'?
Assets/Plugins/RigidAssign.js(7,40): BCE0018: The name 'NetworkRigidbody' does not denote a valid type ('not found'). Did you mean 'UnityEngine.NetworkReachability'?
It obviously doesn't like the "NetworkRigidBody" type, and doesn't seem to know it's been defined in NetworkRigidBody.cs. I've tried adding this to the top:
@script RequireComponent(NetworkRigidbody.cs)
(with and without quote marks around the file name, and with and without the .cs extension).
Know how to tell it about the variable type, or what I missed earlier in the tutorial? Thanks.
Answer by cengizhangokben · Apr 02, 2012 at 07:29 PM
if you want to create a Javascript that uses a C# script: place the C# script in the "Standard Assets" folder and the Javascript outside of the "Standard Assets" folder. The Javascript can now reference the C# script directly.
This is the answer of your problem.
Thank you, I couldn't find this answer anywhere. I'd upvote you but I don't have the reputation.
Answer by BinaryCaveman · Aug 25, 2011 at 01:59 AM
Your code should be valid. However, is NetworkRigidbody.cs
also in the Assets/Plugins
folder?
Make sure that NetworkRigidbody.cs
is in a folder where it gets compiled before (just not after) RigidAssign.js
.
See the Script Compilation page in the documentation for more on this.
Hello! I was having the same problem than blitzen, and this solution to change the file folder solved! Thank you!
Answer by blitzen · Aug 25, 2011 at 02:23 AM
Thanks, they are actually both in the Plugins folder. Any other ideas?
Answer by blitzen · Aug 25, 2011 at 06:05 PM
Also, I just noticed: NetworkRigidbody.cs doesn't show up under the "Component->Scripts" menu. It seems that way for any C# script I create with the "create" button of the Project pane, or with "Assets->Create->C# Script". The behavior seems unpredictable: when I first create C# scripts and name them, about 50% of the time they will show up in Component->Scripts, 50% of the time not. However even for those that do, if I change the contents and save it, or rename it, it then disappears from the menu. This is in the "plugins" folder, though I tried it in other folders like "_Scripts" with the same results. This seems to only be a problem for C# scripts; Javascript files I create get recognized right away.
What is Unity's criterion for which scripts get listed in the Component->Scripts menu? Isn't it for any that are placed in the whole project folder tree? Perhaps this is a clue as to why it's not registering the class from the file.
Here are the contents of my "_Scripts" folder from the StarTrooper networking tutorial:
ConstrainMotion.js MissileLauncher.js MissileTrajectory.js PlayerControls.js RingRotate.js SmoothFollow.js
And here are the options listed in the Component->Scripts menu:
Missile Launcher Missile Trajectory Player Controls Ring Rotate Smooth Follow Terrain
(While we're on the subject, I'm curious why ConstrainMotion.js is not listed in the menu, and where "Terrain" comes from which is not a file name anywhere in the project. Built-in?)
Answer by shinriyo_twitter · Sep 29, 2011 at 05:38 AM
Hi. I guess the plblem of sample below. http://unity3d.com/support/resources/example-projects/networking-example.html
I moved NetworkRigidbody to "Plugins" folder I created. And, I fix it like this [CODE] (GetComponent("NetworkRigidbody") as NetworkRigidbody).enabled = false; [/CODE]
Your answer
![](https://koobas.hobune.stream/wayback/20220612191458im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make car game to multiplayer 1 Answer
Custom master server in the Startrooper multiplayer project? 0 Answers
Help wanted on how to structure a game with separate single- and networked multiplayer. 0 Answers
Photon and the tutorial on cjrgaming.com 1 Answer
Up-to-date Iphone multiplayer tutorial 0 Answers