Search Unity

Heatmaps - All data aggregating to one point

Discussion in 'Unity Analytics' started by QFSW, Nov 7, 2015.

  1. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Hi all

    I tried implementing Unity Heatmaps a few days ago for death, but all the data is aggregating to one point

    upload_2015-11-7_12-54-42.png

    Code (CSharp):
    1. //Death code
    2.     public void Die()
    3.     {
    4.         #if UNITY_ANDROID
    5.         //Viabrates device on death if available
    6.         if(ViabrateOnDeath){Handheld.Vibrate();};
    7.         #endif
    8.  
    9.         //Sets up variables for dead state and respawn stage 1
    10.         Alive=false;
    11.         DeathTimer=1;
    12.         Session.StartTime=Time.time;
    13.  
    14.         //Instansiated explosion effect, and repositions it to the player
    15.         DeathPosition=gameObject.transform.position;
    16.         ParticleSystem Explode = (ParticleSystem)Instantiate(Explosion);
    17.         Explode.GetComponent<PlayerExplosion>().Player=gameObject;
    18.  
    19.         //Disables main fire emitter and resets its parameters
    20.         Fire.gameObject.GetComponent<ParticleSystem>().emissionRate = 0;
    21.         FireStrength=0;
    22.         FireSpeed=1;
    23.  
    24.         //Plays death sound effect
    25.         Instantiate(DeathSound);
    26.  
    27.         //Repositions player to the centre of the screen
    28.         gameObject.transform.position=new Vector3(-4.493752f,-9.49f,0);
    29.         GetComponent<Rigidbody2D>().angularVelocity = 0;
    30.         GetComponent<Rigidbody2D>().transform.rotation=new Quaternion(0,0,0,0);
    31.         GetComponent<Rigidbody2D>().velocity=new Vector2(0f,0f);
    32.  
    33.         //Stores score gained during current life
    34.         //If first life adds entire score
    35.         int n = 0;
    36.         if (Scores.Count==0)
    37.         {
    38.             Scores.Add((int)Session.Score);
    39.         }
    40.         //If not, code adds up all previous saved scores, then subtracts it from the total score to get the amount gained during current life
    41.         else
    42.         {
    43.             foreach (int s in Scores)
    44.             {
    45.                 n+=s;
    46.             }
    47.             Scores.Add((int)Session.Score-n);
    48.         }
    49.         //Logs analytic data on how long they survived for that life, and how much score was gained
    50.         UnityAnalyticsHeatmap.HeatmapEvent.Send("Death",DeathPosition, new Dictionary<string, object>
    51.         {
    52.             { "Lifetime", Lifetime },
    53.             { "Score", (int)Session.Score-n}
    54.         });
    55.  
    56.         //Updates lives and lifetime
    57.         LivesLeft-=1;  
    58.         Lifetime=0;
    59.  
    60.         //If lives are still remaining normal camera shake is called and the spawn animation is reset
    61.         if (LivesLeft>0){Camera.main.GetComponent<CameraScript>().Shake(1.0f);gameObject.GetComponent<Spawn>().ObjectSpawn();}
    62.         //Game over code when no lives are remaining
    63.         else
    64.         {
    65.             //Player rendering and collisions are stopped, as it will not be controllable until a 'Play Again' reset
    66.             GetComponent<Renderer>().enabled=false;
    67.             GetComponent<Collider2D>().enabled = false;
    68.             //Very strong camera shake is called
    69.             Camera.main.GetComponent<CameraScript>().Shake(2.5f,32,4f);
    70.             //Stops spawn code from running and interfering with the collision state
    71.             GetComponent<Spawn>().enabled=false;
    72.             //Game over is initiated
    73.             Session.GameOver();
    74.         }
    75.     }
    76. }
    Does anybody know what's going on? If you need any more information just ask and i will do my best to provide it

    Many thanks in advanced
     
  2. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    For a start, try specifying Space Smooth at a small number like 0.01. Depending on the scale of your game, it's possible that all the points are being aggregated together. Also, since you're not sending time or direction, click 'Aggregate Time' and 'Aggregate Direction'. That might make a difference.
     
  3. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    I tried following your advice and now its just one red square in the middle, thanks though

    Am i doing something wrong or do i just need more data?
     
  4. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    Well, if the data is flowing, you'd expect there to be more than one point, naturally.

    You could try inspecting the raw data visually...just to confirm the contents. It's stored in Application.persistentDataPath in a directory called HeatmapData. Open that file (or those files...there should be more than one) and see what they say. They're fairly human readable. If you only see a single point, then obviously no amount of (dis)aggregating will help. If you see lots of data, the problem must be elsewhere.

    I'll also note that the Lifetime parameter is a teeny bit suspicious, because it's only mentioned after you send the event. But I'm guessing that's simply in some code you've not shared.
     
  5. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Ah yeah, the lifetime is updated every frame and is reset somewhere else, regardless it worked when i had it as a normal custom event before heatmaps were integrated

    give me a moment to check the files
     
  6. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Sorry if this is a stupid question, but where is Application.persistentDataPath?
     
  7. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    OK.

    Oh...this is interesting. Go to the Integration section of Analytics and look at Event Validation (under Advanced > Custom Events). I can see you're sending events, but the three events in the Validator are precisely the same. I'm guessing that maybe you've got a problem with the position of the GameObject at the moment of death.

    Depends on your computer: http://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

    You can find it by dropping it into some code in your game with:
    Code (csharp):
    1. Debug.Log(Application.persistentDataPath)
     
  8. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Ah yes, I know what youre talking about, I think thats because when i was testing it was grabbing the transforms position instead of the var deathposition, I tried it again and they seem to be working fine this time
     
  9. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    I got to the folder you specified but there was no heatmaps folder, only analytics
     
  10. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Do you think its just the case of not collecting enough data since I fixed the problem?
     
  11. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    Yes, the new positions look a lot more like they'd produce a sensible heatmap.

    Give it a few hours to output the new raw data (can be anywhere from ~2-8 hours depending on a few factors). Then try again. I think, based on your data, that Space Smooth of 0.5 - 1 would likely be ideal. And now that you've fixed the problem I think you'll be more pleased with the result once that new data is available.

    You're on Windows and I tend to work on Mac, so maybe it's arranged slightly differently...but the HeatmapData directory should be there somewhere in or near that location.
     
  12. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Ah thank you for all this! I will report back once i see a new processing cycle and see what happens, in the mean time ill be playing the game to get data produced!

    I have a mac which i used to develop on, would you like me to go check it out there?

    Thank you for all the support! this is what i really love about unity
    Best technical support ive ever experienced
     
  13. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    Good plan.

    You could, but at this stage, I'm inclined to think it's just that the data you were sending wasn't right. Still...it'd be useful for you to find the directory, just so you can visually confirm what we think we know.

    We aim to please. :) Plus, it's Saturday and I haven't really gotten past my coffee yet. ;)
     
  14. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Came back today, but there isnt really any new change :(
    Is it because im playing it from the standalone?
     
  15. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Do we have to specifically build them as a development build?
     
  16. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    Nope, nope. You can absolutely build your data out of anything (standalone, mobile, Editor) that can send events (though, as you'll read in the docs, we generally restrict you from putting HeatmapEvents into production).

    So I've just dug into your data and here's what I see: with a "Space Smooth" of 1 and "Aggregate Time" and "Aggregate Direction" both checked, I see 23 unique locations in your heatmap, generated by four unique files (which appear in the Application.persistentDataPath location mentioned above). One of those files (the oldest timestamp) has no Heatmap data in it. The other three have a total of (11+11+27)=49 Heatmap.Death events. The first two files — plus 5 events in the third — have all the events at the same location, as we discussed before. Thus (27-5)=22 unique locations + 1 non-unique location and you get 23, exactly what the Heatmapper displays for me.

    Here's what I get when I render (I've added some notations):

    So my best guess is that there's something wrong in your settings. See what I've done, copy it precisely, and you should get the same result. Hopefully we're getting close to an answer for you!
     
  17. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    upload_2015-11-9_7-34-55.png
    Just tried it again today without changing anything and it worked perfectly! guess I just had to wait longer?
    Also, may I ask why you have changed the thresholds on yours?
    Again thank you for all the support, weve finally got it working! :D
     
  18. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    No worries. Glad it's working. The threshold isn't really relevant for a data set this small. I happened to have it set on mine for a different project.
     
  19. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Is there any word if a gradient based system will ever be implemented? So instead of switching colours at intervals, have it ease?
     
  20. marc_tanenbaum

    marc_tanenbaum

    Unity Technologies

    Joined:
    Oct 22, 2014
    Posts:
    637
    Well, "ever" is a long time. It's not at the top of my priority list, tbh, but you're not the first person to ask. I suppose that if enough people wanted it, it could happen.
     
  21. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Okay, thank you for that, I was just curious about it as i dont really know much about the development of heatmaps