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.

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.

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.

Thanks, they are actually both in the Plugins folder. Any other ideas?

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?)

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

(GetComponent("NetworkRigidbody") as NetworkRigidbody).enabled = false;

Unity Script (specially c#) will not show up in component menu until a script derived from MonoBehaviour class. MonoBehaviour needs to implement various unity3D events and updates.Java script automatically derived from MonoBehaviour.I am runing through same problem. Trying to declare a c# class type in a java script and getting not valid type error message on console.Following link has a details about sequential script compilation

http://unity3d.com/support/documentation/ScriptReference/index.Scriptcompilation28Advanced29.html

I have solved the problem putting script containing c# class in Standard Assets folder and java script outside Standard Assets folder.

Unity Script (specially c#) will not show up in component menu until a script derived from MonoBehaviour class. MonoBehaviour needs to implement various unity3D events and updates.Java script automatically derived from MonoBehaviour.I am runing through same problem. Trying to declare a c# class type in a java script and getting not valid type error
message on console.Following link has a details about sequential script compilation

I have solved the problem putting script containing c# class in Standard Assets folder and java script outside Standard Assets folder.