Automaticly find object with a certain name?

Hi, I’m building a multi player online game, but I want the players rocketlauncher to find the projectile himself, because I can’t store it in the same prefab than the player.

This script should automaticly find the projectile, but it doesn’t:

var projectile : Rigidbody;

function Start() {
	if (!projectile)
		var Projectile1 : Rigidbody = GameObject.FindWithTag("Projectile").GetComponent(Rigidbody);
		projectile = Projectile1;
}

What am I doing wrong, because every time I try it out, there’s a “null reference exeption” with no details about the problem…

Is your Projectile Prefab set to have tag “Projectile”

name is not the same as TAG

Yes, its tag is called “Projectile”, and its name is “Projectile” too, so why does it can’t find the projectile? :?:

… :x
The solution was too easy!
I should simply save the projectiles as prefabs into the project panel, so that the character can access them without finding them in the scene. :idea:

Not 100% sure of this, but make sure a projectile is in the Hierarchy (scene) somewhere, and not just in the project.

The projectile WAS in the scene view and the player couldn’t find it…
Now, it is a prefab in the project view and everything is okay :slight_smile: