Search Unity

Question Recording keypresses and replay them

Discussion in 'Scripting' started by flasker, Mar 15, 2023.

  1. flasker

    flasker

    Joined:
    Aug 5, 2022
    Posts:
    193
    I have looked a bit into command pattern and how to record inputs every frame.

    The goal would be then to replay all the inputs that were recorded over time.

    Assuming my game is a real time rpg and deterministic, is this method expected to yield accurate replay results?

    From the top of my head I can see it failing just because the framerate is never constant, might spike, inputs might have been skipped during recording, or other inconsistencies might happen during replaying?

    Is there a way to make this work accurately without adding snapshots with object positions and interpolations etc, I would like to process the replay only with the input data but I wanted to know if that is just impossible.

    Even a small inconsistency might mean that the player cleared a corner but in the replay its just 1 frame off and so the character will get stuck and from then on the replay is ruined.

    If someone could give their 2 cents I would appreciate it, thanks.
     
  2. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    660
    is there a reason you need the inputs specifically? Can you get away with just recording the transforms[] position?s / rotations , etc?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Achieving true replay determinism is sooooo hard flasker... it is certainly doable, but it is this constant chain-of-custody fight that could be broken at any point by any change into the future, and could be broken so subtly that you wouldn't notice it for a while.

    And the more complex something is, the more chances of something violating your assumptions / perimeter of determinism.
     
    flasker likes this.
  4. flasker

    flasker

    Joined:
    Aug 5, 2022
    Posts:
    193
    well there is no reason other than that it would be very easy to implement, to take advantage of all the movement, animation logic and every interaction, like particles that are triggered from jumping, falling, different based on terrain etc.

    But I see that its too much of an hassle and I don't truly need it, I was just wondering if it was simple, thanks for the replies.

    I think all I have so far is deterministic, unless there's floating point innacuracies that are random, and of course the framerate is random aswell

    (btw in this context I would need only like 40secs of consistency, i dont mind if it breaks for future patches and what not, just trying to replay myself walking through the same exact path through a scene and then just swiching certain assets for a vid)

    and I dont have AI implemented yet so I cant just plot a path for the AI to follow
     
    Last edited: Mar 15, 2023
  5. SeerSucker69

    SeerSucker69

    Joined:
    Mar 6, 2021
    Posts:
    68
    Rather than record inputs, record actions. Move north, cast spell, wait for this time, drink potion etc.
    Record the timestamp for each action, and replay that?
     
    flasker likes this.
  6. I would rather record actions and stuff, because those are more in your own domain as opposed to various inputs. But, with that said, the Input System contains an example how to record input, check it out and play around with it, maybe it's working for you out of the box, maybe you want to modify it or you realize the action-recording is better for your use case.
    Screenshot 2023-03-16 031950.png
     
    flasker likes this.