- Home /
Animation Layers Over Network
I am trying to set my animation.layer over the network. I have
animation[Animations.crouchMeleeAttack.name].layer = 1;
which works perfectly for me. Setting that allows my layer 1 to override my layer 0 animations and I can see the attack as it should happen. Where I don't see results is over the network. I have tried
photonView.RPC("SetAnimLayer", PhotonTargets.AllBuffered, Animations.crouchMeleeAttack.name);
[RPC]
public void SetAnimLayer(string anim){
animation[anim].layer = 1;
}
But no luck.
I get:
NullReferenceException: Object reference not set to an instance of an object
CharacterAnimation.configureAnimations () (at Assets/FPS Kit 2.0 C#/_CustomAssets/Scripts/FPScontroller/CharacterAnimation.cs:316)
If there is a way to set animation layers in the inspector, or a way to set it with an RPC call, that's what I'm looking for.
I'm trying another approach on a flashlight script that I have, but it's also not working.
public bool turnOn = false;
public Light flashLight;
public AudioClip OnOffAudio;
void Start () {
if(turnOn){
flashLight.enabled = true;
}else{
flashLight.enabled = false;
}
}
void Update () {
//Flash light input
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.G)){
turnOn = !turnOn;
flashLightOnOff();
}
}
void flashLightOnOff(){
//Play flash light On/Off sound
audio.clip = OnOffAudio;
audio.Play();
//Activate flash light
if(turnOn){
flashLight.enabled = true;
}else{
flashLight.enabled = false;
}
}
void OnPhotonSerializeView(PhotonStream stream, Photon$$anonymous$$essageInfo info){
bool flashLightEnabled = flashLight.enabled;
if (stream.isWriting){
//We own this player: send the others our data
flashLightEnabled = flashLight.enabled;
stream.Serialize(ref flashLightEnabled);
}else{
stream.Serialize(ref flashLightEnabled);
flashLight.enabled = flashLightEnabled;
}
}
It's telling me:
UnassignedReferenceException: The variable flashLight of 'Flashlight' has not been assigned.
You probably need to assign the flashLight variable of the Flashlight script in the inspector.
Flashlight.flashLightOnOff () (at Assets/FPS $$anonymous$$it 2.0 C#/_CustomAssets/Scripts/WeaponSystem/Flashlight.cs:38)
Though it is actually set in the inspector. Any help would be greatly appreciated on either method.
Answer by alebasco · Aug 21, 2014 at 01:44 AM
An animator controller has layers already. Unless you need to constantly change the layers of an animation (which I can't think of a use for) then you should just set the animation up to be on a different layer in the first place.
As for the flashlight script, if the variable is set in the inspector, my guess is that you might have more than one flashlight, and at least one of them is not set properly.
Trying adding this to your OnOff function
Debug.Log("Turning off", gameObject);
Then when you click on the debug, you can see which object is calling it.
$$anonymous$$y complaint with using the Animator Controller is that I would have to remake my entire animation setup, correct? Or is it something that can be worked on top of a normal animation setup without having to rework the entire thing? Thanks for the response, btw.