Forum rules - please read before posting.

Player Unresponsive after Scene Change

edited January 2022 in Technical Q&A

(Edit: Sorry, posted in the wrong thread and not sure how to move it!)

Hello and Happy New Year!

I have an issue that has proved difficult to describe, so hopefully someone can at least give me some ideas of where to look or what to look at for troubleshooting.

I have two introductory cutscenes for my project. Both of these work fine as I play the scene in the editor. However, if I start with the first scene, my player does not react to actions in a cutscene in the second scene after a scene switch. I'm attempting to change rendering and face direction, but neither seems to work. The Player instead maintains values from the first scene (including a transform scale and direction facing that were changed by a cutscene in the first scene and so are not the player default).

I tried adding in a short delay (both a start delay on the cutscene and an Engine/Wait action in the second scene, in case it needed time to process upon instantiation. This was a strategy I've had to use commonly with other frameworks, but does not seem to work here.

To add to the oddity, after stopping play in the editor in the second scene, and the restarting from the first scene, the Player will have the values expected from the second scene in the first scene. Hitting play in scene one borrows the cutscene values from scene two. If I hit stop at this point and play again, the values return to those expected for scene one.

I'm not even sure how these values would persist from one start to the next.

Any thoughts? Not sure what to post pictures of in this case.

It is my resolution to finish this project in 2022. It's either that or rededicate myself to my treadmill. Isn't this more fun?

Jacob Falling

Comments

  • edited January 2022

    (Moved to Technica Q&A)

    What are your AC/Unity versions, and is this a case of the ActionList itself not running - or are Actions not related to the Player running OK?

    Are the Actions involved inside Cutscenes within the scene they take place, or are they within a single ActionList asset that's set to survive scene changes?

    That the values get applied at the wrong time sounds like there's some bug involved. Are you spawning in a Player prefab, or does either of the scene have a local Player object?

    Your previous post mentioned using Spine - is that the case here? Try assigning the 2D Demo's Player prefab, Brain2D, temporarily to test if that's a factor.

    Any thoughts? Not sure what to post pictures of in this case.

    If in doubt, share anything and everything!

  • Ah, thank you for the swift reply!

    I woke up thinking, "I forgot to mention Spine."

    I'm using: AC 1.73.7, Unity 2019 LTS, multi-skeleton scripts (https://adventure-creator.fandom.com/wiki/Spine_Integration)

    The ActionList are only cutscenes within the scene. They are not stored/prefabs or called separately.

    The Player prefab is spawned in and not already present in the scene.

    The ActionList for the cutscene runs well otherwise, and the only problem seems to be with the actions affecting the Player rendering and facing (so far). For instance, I can run 1) dialogue actions for the Player (it utilizes the Player label and portrait) and 2) Rendering actions for NPCs already present in the scene (and who are also using the Spine setup).

    I will try testing with Brain when I am able. I also have a demo project set up with Spine that may help eliminate some variables, but this involves scene switching so I would not have discovered this there yet.

    -Jacob

  • I'm not sure about the facing-direction, but the rendering issue looks to be caused by the Spine integration affecting the character's prefab, rather than the scene instance.

    Inside the AnimEngine_Spine script, replace the instances of:

    action._char
    

    with:

    character
    
  • Just made that quick change, and it mostly works.

    It makes some intuitive sense that it's effectively queueing (five vowels in a row!) actions on the Prefab, that will then only take effect after persisting into the next scene, but that's something I'd like to understand better and will research.

    This fix does seem to adversely affect the face direction action, though -- It is now triggering a walk animation, which makes the character seem very rude. It was a polite conversation, and she just walked away in the middle of it.

    I wonder why these choices were made in the script? It seems like it would affect about any project, unless subsequent AC changes made a difference.

    I'll play around with this a bit and work to understand the scripts better. Really appreciate your support!

  • I'm not the script's author, but I suspect it was just a mistake rather than its intent. The mistake is not made for its implementation of other animation-related Actions.

  • The walking issue above turned out to be inconsequential -- I simply had my cutscene running in background, so my Player was following a mouse click as a good Player should.

    I do still have the facing direction issue, unfortunately. Neither the action nor Player control changes facing. Only the Change Rendering action allows me to switch character directions. This aspect was functioning before making the changes above.

    Any thoughts on what I'm looking for?

  • AC handles which direction a character is facing, but it's still up to the AnimEngine to process that into a directional animation.

    Assuming the former is working (you can check this by swapping out your Player prefab with that of the 2D Demo, Brain2D), the Spine integration handles directional animation via the DirectionMapper script.

    Inside that script there is a SetCurrentDirection function, which takes a parameter for the direction as a suffix (e.g. "_D" for down, "_R" for right etc). I'd place a Debug.Log statement inside that to check that it's being called with the correct parameter value, i.e.:

    Debug.Log ("Set direction: " + newDirection);
    

    If this function runs successfully, it should then call the same script's SetSkeletonDataAsset function. If the above causes Console logs are correct, try the same thing in this second function.

  • The suffixes appear as expected when the ActionCharRender script fires, but it does not change when moving the Player, or when using ActionCharPathFind, ActionCharFaceDirection on the Player or an NPC (rather already present in scene or instantiated from Prefab).

    I looked at the ActionCharFaceDirection script as an example. I can't quite unravel where the facing would change in here, but it seems that the directionParameterID = -1 remains throughout.

    The last function of the script that creates a new instance of the action (ActionCharFaceDirection) does not seem to fire, but I'm uncertain the purpose of this. Adding a debug.log to these in other (functional) actions also does not produce a comment.

    I've basically just started commenting all over the place to get an idea of how the scripts flow, but it's a challenge since these scripts fire every frame -- even a one second run fires >999 of my debug logs.

  • The suffixes appear as expected when the ActionCharRender script fires, but it does not change when moving the Player, or when using ActionCharPathFind, ActionCharFaceDirection

    The AnimEngine script only deals with the character's animation - so Actions and commands related to the character's movement will not be covered by it.

    The AnimEngine_Spine script's PlayStandardAnim function, however, should be used to set the correct direction.

    Check that this is being called correctly with another log. You can filter this to only show for the Player with:

    if (character && character.IsPlayer) Debug.Log ("Player direction: " + character.GetSpriteDirection ());
    

    What was the result of placing logs in SetSkeletonDataAsset?

    directionParameterID = -1 remains throughout.

    Unless you're overriding the Action'sDirection field with a parameter, this is correct.

    The last function of the script that creates a new instance of the action (ActionCharFaceDirection) does not seem to fire

    This function allows you to generate an Action through script at runtime - it can be ignored. More on this topic can be found in the Manual's "Generating ActionLists through script" chapter.

  • The AnimEngine script only deals with the character's animation - so Actions and commands related to the character's movement will not be covered by it.

    Makes sense.

    I just mean that moving the character in a new direction via mouse click does not change the direction, nor do the referenced action - i.e., only the Change Rendering action works as expected. For all other actions and for mouse movement, the character moves as expected (to the click or to a marker) but does not change facing direction.

    I'd also reiterate add that these actions and mouse control worked as expected (though without a scene switch) before changing the AnimEngine_Spine script as you suggested before: to switch references from action._char to character

    This effectively solved one issue and revealed another.

    What was the result of placing logs in SetSkeletonDataAsset?

    I'll try to trace a chain of events starting with ActionCharFaceDirection since I can isolate it.

    • Player is only character in scene
    • Cutscene is set to fire on start
    • Actions include:
    1. An engine wait of 0.1 seconds (first player action doesn't fire without this)
    2. Character Face Direction (Player, Down, Instant)
    3. An engine wait of 0.1 second + (toggle breakpoint)

    Hopefully these debug logs will more or less make sense.

    Prior to the Face Direction action firing, the AnimEngine_Spine and associated scripts run 4 times.

    The following happens in the very first iteration (but never again):

    SetSkeleteonDataAsset is Sprite polly parts 2_SkeletonData (Spine.Unity.SkeletonDataAsset)

    Onto the Face Direction action

    `Script: ActionCharFaceDirection; Function: Run; Vector 3; direction = Down; lookVector = (0.0, 0.0, -1.0))'

    That looks right to me. The Player begins facing Up, so this represents a change from the action.

    The breakpoint fires here, so nothing further. until I unpause the engine. Then the AnimEngine_Spine cycle starts again. It runs probably 30 times in the time it takes me to unpause and pause again, which I assume amounts to every frame.

    Script: AnimEngine_Spine; Function: PlayStandardAnim Polly (AC.Player)

    Script: AnimEngine_Spine; Function: SetDirection

    Script: AnimEngine_Spine; Function: DirectionMapper

    Jumps over to DirectionMapper...

    Script: DirectionMapper - Function: SetCurrentDirection

    currentDirection = _U

    So definitely not getting the memo there. It's not getting to SetSkeleteonDataAsset, so my assumption is that currentDirection and newDirection are the same at this point.

    Yeah, quick edit confirms:

    currentDirection = _U newDirection = _U

    ...after ActionCharFaceDirection set to Down.

    Back to AnimEngine_Spine for posterity's sake...

    Script: AnimEngine_Spine; Function: PlayStandardAnim; Player direction: _U

    Script: AnimEngine_Spine; Function: PlayCharAnim

    Script: DirectionMapper - Function: PlayClip = idle

    Loops from there.

    Aside:

    This function allows you to generate an Action through script at runtime - it can be ignored. More on this topic can be found in the Manual's "Generating ActionLists through script" chapter.

    Ah, so the actions effectively have a template for themselves as a function. Wow, that presents a whole other level of possibilities. Down the rabbit hole and through the looking glass.

    Just being able to nest actions will probably be enough for this project and can work some wonders, but dynamically creating actions could be a fantastic next leap. I think I completed the Wonderland metaphor there.

  • Thanks for the log details. Have you tried using Brain2D with your Actions?

    If the character is only turning when the direction is locked, then it sounds like it could be an issue with the character's SpriteDirectionData.

    This class deals with what directions the character can face. It should be shown within your character's Inspector as a popup field named "Facing directions". As this is reserved for 2D characters, it's called by the AnimEngine - but I've checked the AnimEngine_Spine class and it is correctly called.

    What directions are enabled for your character?

    Each frame that a character's direction is unlocked, the SpriteDirectionData class's GetDirectionalSuffix function is called to convert an angle into the directional suffix ("_D", "_R" etc). As we're now dealing with AC's own scripts, it's hard to say where the fault exactly lies - but that'd be the next place to put down Debug.Logs to work out what's being returned.

  • edited January 2022

    Thanks again for the help!

    I'm using 4-direction control (at least until I can talk my wife/artist partner into 8... :-)) and have Skeleton assets added for all. Again, everything works when I use the change rendering action.

    https://photos.app.goo.gl/UAFJAUg2NYU7Gnwx6

    For the record: In my above scenario (two posts up), I removed the ActionCharFaceDirection and replaced it with ActionCharRender.

    Here the Direction Mapper correctly picks up the newDirection as _D, recognizes the mismatch (currentDirection != newDirection), and assigns the new skeleton

    Script: DirectionMapper - Function SetSkeletonData Asset

    SetSkeleteonDataAsset isSprite polly parts 2_SkeletonData (Spine.Unity.SkeletonDataAsset)

    Script: AnimEngine_Spine; Function: PlayStandardAnim; Player direction: _D

    Etc.

    I put a couple of debug logs in SpriteDirectionData GetDirectionalSuffix... it doesn't seem to be called in anything I'm doing, either actions or mouse movements.

    I'm not sure how to test with Brain.

    Switching in Brain as the Player works while using the Sprites Unity animation engine.

    Is it actually worth rigging a set of Spine skeletons for him? Doesn't feel like that will gain us anything here. I already have several, and this would likely just replicate the same variables with a different model.

    Thank you for linking to your scripting guide. It is fantastic.

    You mentioned the direction locking/unlocking now, so I'm wondering of the prior changes I made from in AnimEngine_Spine from

    action._char

    to

    character

    have caused unforeseen consequences.

    I'm not sure what this does exactly, though I'll try to puzzle it out, but the areas I changed seem to all override the locking of the ActionCharRender action, such as:

    if (action.renderLock_direction == RenderLock.Set)

    {character.SetSpriteDirection(action.direction);}

    else if (action.renderLock_direction == RenderLock.Release)

    {character.lockDirection = false;}

    etc. for sorting map, scale, and other lockable settings.

    I assume these are just translating from one script/function to another, but it's the only thing I've actually changed at this point apart from logs.

  • I removed the ActionCharFaceDirection and replaced it with ActionCharRender.

    If you're doing that, then the character's direction is forced - and not calculated by GetDirectionalSuffix. You will need to revert back for a reliable test.

    Switching in Brain as the Player works while using the Sprites Unity animation engine. Is it actually worth rigging a set of Spine skeletons for him?

    No - this was a test to isolate the cause of the issue, i.e. the character's direction commands vs the animation engine. Knowing that Brain works as intended is enough.

    I'm wondering of the prior changes I made from in AnimEngine_Spine from action._char to character have caused unforeseen consequences.

    By all means, revert them and test - but from what I can see it's a case of having the Action affect the original prefab vs the runtime instance of the character.

    A way of testing this would be to place a pair of logs that can be clicked to "ping" the associated objects:

    Debug.Log ("action._char", action._char);
    Debug.Log ("character", character);
    
  • Understood. Some of this is more for me to understand the differences between moving the Player and between various actions, so I'm having to take a few more smaller steps to catch up with you. I've been adding logs all over the place so I can understand the overall workflow better.

    I'll take some time to delve more into this with the direction you've given and with the help of the scripting guide.

    It seems pretty clear that these are not issues with AC itself, but with the third-party Spine integration scripts. I actually had about an hour of playable (but only partially animated) game completed before switching to the Spine-based animations, so thank you again for a fantastic framework and for all of your time!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.