Photon Animator View - What about Triggers?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Photon Animator View - What about Triggers?

wieljer
2016-04-20 18:10:42

I see there is probably no way to auto pull triggers by default with this script for animation. However since the Trigger section does not have any comments on how it should be handled in this class, I'm hoping to get some idea on what to place within the trigger case. Currently I am using an RPC from the characters controller script but I feel I can better optimize and make the code more efficient by adding it to the SerializeData?

                switch (parameter.Type)  
                {  
                    case ParameterType.Bool:  
                        stream.SendNext(this.m_Animator.GetBool(parameter.Name));  
                        break;  
                    case ParameterType.Float:  
                        stream.SendNext(this.m_Animator.GetFloat(parameter.Name));  
                        break;  
                    case ParameterType.Int:  
                        stream.SendNext(this.m_Animator.GetInteger(parameter.Name));  
                        break;  
                    case ParameterType.Trigger:

                        break;

I really love this script and I would hate to have to use a RPC for a trigger (anim property) if there is a more efficient way to use serialization within this class I would love it if someone could give me an example using it with a trigger :) !

Comments

JohnTube
2016-04-21 11:25:28

Hi @wieljer,

Maybe you can find what you're looking for in the new Photon Animator View Triggers doc page: https://doc.photonengine.com/en/pun/current/reference/animatorviewtriggerhelp

wieljer
2016-04-22 14:40:10

Hi @JohnTube,

Sadly this did not cover the type of information I am seeking. Let me try to break down my original query a little more simply. Hopefully this clarifies my question:

How do I use Triggers with the Photon Animator View? (examples would be nice)

jeanfabre
2016-04-25 16:36:21

Hi,

Chances are that if you tried it in your project it did not work at all because support was missing.

Luckily for you, we've just added triggers support, so if you get the latest version of pun on the asset store, triggers will now work properly.

I am working on a sample that will demonstrate the use of triggers and will be likely shipped with the next version of PUN. but in short you only need one call:

.SetTrigger("Trigger name")

However, you need to be careful with another aspect, your script must be above the PhotonAnimatorView for Unity to have time to raise the trigger flag to true and the PhotonAnimatorView to then catch it, so the ordering of components on GameObjects is very important in the case of triggers.

Let me know if that still doesn't work with you after updating PUN, ok? I can send you the working sample as an individual package so that you don't wait for the next release.

Bye,

Jean

wieljer
2016-04-26 02:03:02

Hi @jeanfabre

Yup this update did the trick, I can remove all those messy RPC conversions now! This will save me so much time thanks!

Appreciate you jumping in and answering this one for me!

jeanfabre
2016-04-26 06:12:00

Hi,

You are welcome, feel free to pm me and mention problems you posted but did not get any answers.

Bye,

Jean

wieljer
2016-05-10 02:29:44

@jeanfabre I updated again today, I noticed that the DemoMecanimGUI does not have these new parameters for the triggers showing :) - I went ahead and added the lines of code. Now with the Trigger showing in the GUI I also noticed that when sending the trigger it is received by my own 'received' values even though I sent it to my remote instance. All other parameters seem to be fine its just triggers ?

jeanfabre
2016-05-10 10:22:58

Hi,

ok, there may be some confusion here.

-- DemoMecanimGUI doesn't use trigger, the demo I am working on is not yet release and will use an edited version of the Animator controller that will have the jump parameter as trigger.

-- I am not sure what ou mean by "Sending the trigger", normally you just use .SetTrigger("Trigger name") and the Photon Animator View does the rest ( if you have enabled synchronization for the parameter).

so maybe you could detail a bit more your issue with the received values and the remote instance?

Bye,

Jean

wieljer
2016-05-10 20:36:02

@jeanfabre

Thanks for the response and sorry for the confusion, I'll try to clear that up:

-- I updated the DemoMecanimGUI script myself to include the bool value for the trigger (because I found it very useful when prototyping my project and wish to continue using it).

-- In the PhotonAnimatorView - ParameterType.Trigger ... Animator.GetBool(parameter.Name). The DemoMecanimGUI finds this component and displays the trigger {send & receive} values (because I added the trigger to the DemoMecanimGUI).

When the boolean is sent representing the state of the trigger, it is received by the local client sender. The DemoMecanimGUI revealed this to me, perhaps I will just wait for the next update so I can see how you have it configured :)

Thanks!

jeanfabre
2016-05-11 05:59:10

HI,

Have you refactored the Animator Controller to use a trigger instead of a boolean for its parameter?

I'll send you this afternoon a package with the demo I am working on, so that you don't have to wait.

Bye,

Jean

wieljer
2016-05-11 13:38:40

Okay sounds great! Really appreciated

jeanfabre
2016-05-12 13:16:03

Hi,

Sorry, it took longer than expected,

Please download it below
https://dl.dropboxusercontent.com/u/17356625/Unity/ExitGames/demoTest.unitypackage

Be aware, this is a work in progress, so use a fresh project, dedicated for this, to not pollute your production projects.

Let me know if you don't find what you need, but basically, it's the same as the current mecanim demo but using a trigger parameter for jumping.

Bye,

Jean

wieljer
2016-05-13 16:05:26

@jeanfabre Great thanks, I've downloaded it and will try it out tonight!

wieljer
2016-05-14 20:32:33

@jeanfabre - i tested this out and took a look at the logic behind it. Seems like it works logically but there does seem to be missed packets or perhaps updates that are sent too late. The video below you can see when jumping the trigger isn't always received on our remote instance of our-self. Once in the very beginning of the video and near the end you can see this occur. This is a really nice demo though, I have some triggers that are essential to be received in the right order before other triggers can occur so if one is missed then I'm in trouble :(

https://youtu.be/8CUKeaK_1u8

Perhaps we can figure this out together ! Thanks for your assistance, I will test anything you have :)

jeanfabre
2016-05-16 11:33:00

Hi,

Interesting, and you haven't touched the Player Prefab?. What version of Unity are you using?

Typically, to solve this, you need to be aware of the Unity restriction regards Triggers. since they only exists between the time you raise it and the end of the frame, it's important that the component that raise the trigger is processed before the PhotonAnimatorView ( so that it's true already). so open the Player prefab in the resource and check that the "PhotonAnimatorView" script is the last component on the stack, or that at least the "PlayerAnimatorManager" script is above the "PhotonAnimatorView" script.

so nothing is missing regards Photon and packets, it's simply on the GameObject itself that the trigger is never caught true because set after the "PhotonAnimatorView" did it's job for that frame.

Let me know how it goes,

Bye,

Jean

wieljer
2016-05-17 01:29:06

@jeanfabre I just gave it another go in a new project but have the same results from both Master and Client receiving it. I haven't touched anything really just a straight import of PUN+ and then Import package, enter my PUN ID, add scenes to build order then build the application and run two instances.

I double checked the player prefab and the "PlayerAnimatorManager" script is above the "PhotonAnimatorView" script.

I'm running Unity 5.3.4f1 and PUN+ 1.68 on Windows10

jeanfabre
2016-05-17 11:16:50

Hi,

ok, that's not cool at all... I can't repro this, I tried on 5.3.4 P5 and the latest pun 1.68 from the asset store. Maybe this is a windows issue?! but that would be very bad if that was the case..

one thing that you can do right now to progress while I get to the bottom of this issue.

simply remove the PhotonAnimatorView from the prefab and add it again, and set it up to have all the parameters synched and try again. The goal is to shake the prefab component order so that it's correctly.

Can you also check that your Script Execution order editor settings are clean from any overrides?

http://docs.unity3d.com/Manual/class-ScriptExecution.html

Bye,

Jean

jeanfabre
2016-05-17 11:18:04

Hi,

one more thing. In order to quickly test this, you don't need to publish, you simply run in the editor, and select the instanciated player, and watch the PhotonAnimatorView parameter change in real time as you control them, if you don't see the jump parameter being set to TRUE when you jump. no need to deploy and test with two running applications.

Bye,

Jean

wieljer
2016-05-18 01:48:50

I had some odd issues, take a gander at this video
https://youtu.be/DNjRJP0ZX8Q

jeanfabre
2016-05-18 11:30:54

Hi,

Good catch with the warning. It's fixed now, you can safely ignore this however.

As for the problem with jumping, I can finally repro this locally, and it looks bad because even the animator Controller doesn't seems to catch the Trigger and update the parameter, while actually acknowledging the flag and executing the transition, so I'll file a bug report.

I'll get back to you when I get a proper way of working with this. It's really odd, we already faced this when I initially started working on this, and it seems it came back with a vengeance! :)

Bye,

Jean

jeanfabre
2016-05-20 11:31:13

Hi,

ok, I got it. It was a mix up of many small issues.

  • Now it's properly using triggers
  • Discrete and Continuous options are both supported when you want to synch triggers using PhotonAnimatorView ( it was only working with continuous)

Please redownload from the dropbox link

https://dl.dropboxusercontent.com/u/17356625/Unity/ExitGames/demoTest.unitypackage

let me know if that fixed it.

Bye,

Jean

Brodyaga
2017-01-19 05:30:26

@jeanfabre,
Triggers are not synchronized. I'm using the latest version of PUN. Component at the end.

jeanfabre
2017-01-19 11:32:58

Hi,

You can confirm this is working by checking the PunBasic Demo, the jumping is done using a trigger. So publish the demos, test and if jumps appears across all instances then triggers are fine, and something isn't setup properly in your scene, animator or code.

Let me know if you can't get anywhere with this.

Bye,

Jean

Brodyaga
2017-01-19 13:23:32

@jeanfabre, In the Demo scene jump not working. The latest version of Unity.

jeanfabre
2017-01-19 13:35:03

Hi,

uhm, yes, I can repro this on 5.5. It works on 4.7, something has changed apparently. investigating.

Bye,

Jean

jeanfabre
2017-01-19 14:08:27

Hi,

Can you switch from discrete the Continuous for the trigger serialization option in the PhotonAnimatorView. This did the trick here, but I haven't found yet why it stopped working for discrete...

Let me know if this works for you on your end., then I can investigate further as to what changed.

Bye,

Jean

Brodyaga
2017-01-19 14:27:03

I have tried discrete and continuous. In any case, it is not working.

jeanfabre
2017-01-19 14:34:56

Hi

interesting...

can you try copying the photonanimatorView, deleting it and then pasting it as new and see if it works then ( don't forget to observe it again from the photonView)? basically what is likely happening is internally the order of execution between the component is shuffled and it not reflecting the visual order in the inspector

Bye,

Jean

Brodyaga
2017-01-19 14:58:59

And I also did, but to no avail

jeanfabre
2017-01-19 15:48:44

Hi,

what version exactly of Unity do you have and what version of PUN?

Bye,

Jean

Brodyaga
2017-01-19 16:07:04

Unity 5.5.0f3. PUN 1.80

jeanfabre
2017-01-20 13:28:59

Hi,

I am puzzled, as I can always get it to work here under the same version of Unity and PUN. Are you using the demo for this or did you switched already to another scene?

Bye,

Jean

Brodyaga
2017-01-21 18:11:12

The trigger works sometimes, if you try constantly to activate it.

jeanfabre
2017-01-21 18:14:52

Hi,

yes, but that's no solution :)

I'll try on monday the alter the execution order of scripts, this is something that likely will help. but I haven't tested this yet, I'll get back to you on this.

Bye,

Jean

jeanfabre
2017-01-23 12:23:21

Hi,

ok, so execution order doesn't help. The only way for me to make it work is to use "Continuous" for the trigger animator entry.

Can you confirm you are testing on a fresh project with just Photon ? If not can you give it a try like that?

Bye,

Jean

Brodyaga
2017-01-24 10:13:53

Use Photon Unity Networking v1.80

Brodyaga
2017-01-24 10:15:20

Playmaker 1.8.3

jeanfabre
2017-01-24 10:28:16

Hi,

So you are using PlayMaker to control the animator trigger?

Bye,

Jean

Brodyaga
2017-01-24 18:50:49

Yes

jeanfabre
2017-01-25 11:39:45

Hi,

ok, I confirm that it works too with PlayMaker controlling the trigger.

you must have the following:
-- Trigger set to continous in the PhotonAnimatorView
-- PhotonAnimatorView MUST be the last item, if you move it down it doesn't help, you have to copy it, delete it, pasting it as new, and drag it back into the photonView Observed field.

Bye,

Jean

Back to top