Hello Guest

Author Topic: Setting (and using) correct platform  (Read 6339 times)

habitoti

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
    • Rombos Homepage
Setting (and using) correct platform
« on: March 04, 2014, 06:11:13 am »
Hi,

I am trying to get along your platform support docs (and all the threads here around it). I am failing already early, because setting the platform support in code does not work correctly for me. I set it in a specific setup script really early in the startup phase (backed by an explicit early script execution order) like this: tk2dSystem.CurrentPlatform = "2x";
I added a log to your currentPlatform getter, and it is already correctly set to "2x" the first time it is being requested at all. However, at runtime the affected sprites are still pointing to the 4x atlasses. If I set it manually in tk2d Prefs, however, they correctly point to the 2x atlas.
I assume I missed one important additional step -- I simply don't know which...

Thanks, habitoti
Checkout our homepage or visit the Rombos blog.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Setting (and using) correct platform
« Reply #1 on: March 04, 2014, 11:14:54 am »
Try setting in a separate scene and switch to the main scene just to make sure everything is working properly. If it does, check that CurrentPlatform is working as expected - put some debug logs to make sure its actually calling it as you expect - Debug.Log in tk2dSpriteCollectionData.Init to make sure CurrentPlatform is set before it gets in there.

habitoti

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
    • Rombos Homepage
Re: Setting (and using) correct platform
« Reply #2 on: March 04, 2014, 12:39:49 pm »
Added log to tk2dSpriteCollectionData.Init, and platform is switched already to 2x on first call. However, in contrast to using tk2d prefs, the running game does not use 2x atlasses...
Checkout our homepage or visit the Rombos blog.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Setting (and using) correct platform
« Reply #3 on: March 04, 2014, 12:48:58 pm »
I'd just step through Init to see if its already initialised - I have seen rare cases where Unity doesn't correctly unload collections which are already loaded as its supposed to when going into play mode - its annoying but I've not really bothered investigating much further as it doesn't affect runtime.

habitoti

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
    • Rombos Homepage
Re: Setting (and using) correct platform
« Reply #4 on: March 04, 2014, 04:28:32 pm »
Looks like the collection is loaded into editor already with of course just considering the tk2d prefs settings, and on running, the already loaded collections are not purged and reloaded, but rather continue to be used in that setup. Not sure whether this is now the "rare" edge case you are describing above, but I believe when the platform is set in code, something like the PlatformChanged() call does (when changing prefs) would have to happen at that point in time (i.e. purging existing collections). But setting the platform has no such side-effects at all...
« Last Edit: March 04, 2014, 05:12:13 pm by habitoti »
Checkout our homepage or visit the Rombos blog.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Setting (and using) correct platform
« Reply #5 on: March 04, 2014, 06:37:03 pm »
It shouldn't be loaded in - basically when you press play, everything should be unloaded and loaded back in. Thats why I was asking for Debug logs to definitely be sure it was doing it in the right order - you can verify if its loaded by setting a breakpoint in spritecollectiondata.Init and steping through it.

Setting the platform doesn't and should not have to purge anything as nothing should be loaded at that point...
I suppose you could hack it to do so, but it won't be behaving like it does in game - eg. in game if you load 2x assets you can't then switch to 1x, and that is intentional and expected.

habitoti

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
    • Rombos Homepage
Re: Setting (and using) correct platform
« Reply #6 on: March 04, 2014, 07:14:22 pm »
Right, but as a matter of fact, the collections that are required to display the editor data won't be purged on start...I've put in logs to show which collections are loaded after start, and these are not, but are rather already loaded and initialized during edit mode.
Checkout our homepage or visit the Rombos blog.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Setting (and using) correct platform
« Reply #7 on: March 04, 2014, 09:20:06 pm »
Ah but this is not correct behaviour. If it stays resident it is usually for some reason - usually because Unity needs to save the collection for some reason. Do you get an "Upgrading" message or similar when first using it?

habitoti

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
    • Rombos Homepage
Re: Setting (and using) correct platform
« Reply #8 on: March 04, 2014, 10:19:29 pm »
No, nothing...
Checkout our homepage or visit the Rombos blog.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Setting (and using) correct platform
« Reply #9 on: March 04, 2014, 10:36:59 pm »
Check in the profiler memory report thing - it usually tells you why something isn't unloaded...