- Home /
Question by
Drakeshe · Feb 25, 2012 at 10:28 AM ·
gameobjectmonobehaviouraddcomponent
Can't add component because class doesnt exist
Hey, I'm currently trying to implement remote adding of components using an RPC call. I use it like this. Unfortunately each of these will result in an error saying "Can't add component because class 'SwordBehaviour' doesn't exist!"
. Can anyone figure out why im getting this? //Weapons.cs public class WeaponBehaviour : MonoBehaviour { } public class SwordBehaviour : WeaponBehaviour { }
//Main.cs
void asdfg()
{
AddComponentToRPC(networkView.viewID, typeof(SwordBehaviour).FullName);
//Also tried
AddComponentToRPC(networkView.viewID, typeof(SwordBehaviour).Name);
AddComponentToRPC(networkView.viewID, "SwordBehaviour");
}
[RPC]
void AddComponentToRPC(NetworkViewID viewID, string behaviourType)
{
NetworkView.Find(viewID).gameObject.AddComponent(behaviourType);
}
Comment
Answer by Dreamora · Feb 26, 2012 at 09:10 AM
For components to be correct, you need to put them into different files, one per monobehaviour, each of these files having the same name as the class.
In this case though it might also simply be a typo as you send a string which does not verify the existance at compile time at all.