Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

2D Physics Puzzle Kit

Discussion in 'Assets and Asset Store' started by Dreeka, Dec 7, 2013.

  1. cdutoit

    cdutoit

    Joined:
    Jul 20, 2013
    Posts:
    34
    Hi- I love the kit - a really good example of coding. However, I am experiencing what may be a memory leak and looking for the authors comments, or anyone else here who may know Unity far better than I do.

    When I deploy to my ipad, I use instrumentation on xcode to see the cpu and memory usage. As I move from level to level, the memory usage just keeps growing. CPU usage stays constant but by level 8 of the game I'm over 300mb of used data. Going from one scene to the next does not release memory used by the previous scene.

    I don't know if its the static class references being held on to or if I need to explicitly call an unload or destroy somewhere? Since I'm fairly new to Unity, I appreciate any and all recommendations as to what I can look at or try.

    Thanks
    Chris
     
  2. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    I'm not seeing that with my project (deploying to Windows on a PC and a tablet). Whenever changing screens I get a message like the following in my debugger:

    "Unloading 24 unused Assets to reduce memory usage. Loaded Objects now: 514. Operation took 12.196716 ms.
    System memory in use: 13.3 MB."

    I've not seen memory usage rise above 14.1MB so far.

    I did change the menu system in my game (by adding a 2nd tier - Main screen > Level sets > individual levels), but I don't think that would change much. My game is also using added sound effects and particles, as well as my own extra graphics, music, and prefabs. So I think you have a leak somewhere.

    Try deploying to a different platform (PC/Mac). Maybe the issue is specific to your iPad.
     
  3. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    pumpkinszwan:
    You can easily add multiple goals by defining a second set of target/goal. Then only show the finish screen, if both of the goals are completed.

    widebeam:
    In the main menu, you have to check the "use touch" in the "Main" object.

    pumpkinszwan:
    The mobile input is not as perfect as the PC input. I will improve the touch controls in the next update.

    RandAlThor:
    Bigger screens are not supported out of the box, but you can modify the kit for it.

    cdutoit:
    I haven't experienced memory issues. Did you made modifications to the kit?
     
  4. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    Thanks for the response. I think I found a cause for my touch issues - I had modified the code to turn the GUImanager into a prefab, but this seemed to cause some issues. Ensuring all the GUImanagers were unique items, rather than inherited from a prefab seems to have solved my issue.

    I will work on multiple goals. I'm loving the toolkit.

    I have a small request for the update: include images for digits '9' and '0' to allow for levels above 8. I am currently using 12 levels per set in my game.


    Has anyone come up with additional objects? I've created a cannon that shoots another item when triggered, and am working on a see-saw and fan, but both are not yet working very well...
     
  5. cdutoit

    cdutoit

    Joined:
    Jul 20, 2013
    Posts:
    34
    Memory Leak (continuted)...

    Apologize for the long post but I wanted to provide details.

    I started a new clean project and used the 2dPhysics kit AS IS. No modification. I just do a Build and Run on a clean instance. Please see my chronological walk through below.

    Game/Home Screen
    First is when I run and get to the main game screen. It stays at around a constant 14mb. So far so goo:



    Level Screen
    Then I go to one of the levels and start playing. If I try drag an item from the toolbox (note there is an ipad bug where the feedback circle doesn't go green) and try drop an object on the scene. Because the feedback circle stays red, it jumps back to the toolbox. However, notice the memory growing in almost a linear fashion. At this point i'm not even doing anything. The screen is still there in "stop" mode:



    I let it sit, not touching anything - watch the growth -after about a minute its already reached 84mb:



    You can see a linear growth.

    Back to home screen
    Then I use the option to go back to the home game screen. Notice now that the memory consumption no longer increases, stays level, but the previous memory is not freed up. Already at almost 100mb.



    Back to a Level screen
    Now I go back to another level screen, attempt to drag a toolbox item, and again you see the memory climb sharply. And it continues to grow without me doing anything else:



    The CRASH
    Finally just sitting there you will see memory warnings followed by the fatal crash:



    Again, this is a 100% clean project, no modifications. Unfortunately this renders it unusable so I really appreciate your urgent attention to this issue. I don't know if this helps or not but I'm having the same issue as experienced by somebody who left you a review who said that there is an issue on the ipad when the feedback circle never turns green. I have this same issue and notice that memory is being consumed after I attempt to, unsuccessfully, drag a toolbox item to the screen.

    EDIT 1: This occurs whether you use the JS or C# version.
    EDIT 2: The red feedback ipad bug is a red herring. Even if I drop a item on the screen successfully, the memory consumption starts growing once I touch somewhere to remove the feedback circle.
    EDIT 3: Same problem on iPhone

    Looking forward to your response,

    Thanks
    Chris
     
    Last edited: Mar 2, 2014
  6. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    I've created a replacement GoalManager script for using multiple goals in a level.

    Note: if you use this script it will completely replace the original one, and therefore you will have to change all existing levels (i.e. you will have to re-assign the goals/targets). For levels with a single goal you just use an array size of 1. The script allows you to drag and drop your target/goals in the editor just like the original, except now you can have more than one goal.


    Also note: I haven't tested this extensively, but it's so far working well for me. There is quite a bit of explanation in the comments, but feel free to post here if you need more info, or use the email address in the script comments.

    http://1drv.ms/1dT3BnW

    EDIT: Also please note that this is not made by the creators of the 2D Physics Toolkit, so they can't be expected to help you if this doesn't work. I will respond to emails and comments in this thread to the best of my ability.
     
    Last edited: Mar 3, 2014
  7. KeepTrying

    KeepTrying

    Joined:
    Feb 23, 2011
    Posts:
    119
    Dreeka, got my message ? ._.
     
  8. UltraTM

    UltraTM

    Joined:
    Dec 8, 2013
    Posts:
    221
    Still waiting for Updates with second leves page :(
     
  9. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    First of all, sorry for the late reply! From monday to thursday, I spend most of my time at university, so my free time is rather limited in those 4 days.

    pumpkinszwan:
    You can download digit 9 and digit 0 from here.

    cdutoit:
    Thank you for bringing this to my attention in this much detail. I will look into it in the weekend.

    pumpkinszwan:
    Fantastic work, good job! :)

    KeepTrying:
    Answering your PM after this post.

    UltraTM:
    Sorry for the delay, I try to do it in the weekend.
     
  10. nickthegreek

    nickthegreek

    Joined:
    Jan 31, 2014
    Posts:
    12
    Script does not work on older Android devices. For example in my Galaxy Tab 10.1 the game starts but when playing a level every item is red and cannot be plased in the scene. The performance is poor, about 10 - 15 fps. Any solutions to that?
     
  11. cdutoit

    cdutoit

    Joined:
    Jul 20, 2013
    Posts:
    34
    Hi Dreeka -

    RE: Memory Leak
    I believe I have found the memory leak.

    In FeedbackManager.cs, the Disable() method needs to have this line added:

    this.target = null;

    Without it, the update method will constantly attempt to manipulate the transform. It's interesting that it eats memory, but nonetheless, nulling that object stops the memory consumption. This is also what eventually drops the FPS. Please review and see if that is indeed the required fix. I'll gratefully accept payment in terms of a copy of your 2d infinite runner kit ;)

    Feedback Circle
    Regarding the issue people are experiencing on mobile where the feedback circle goes red, I seem to have fixed it but in an ugly way. This is probably not the best fix but I'll bring it to your attention if it helps you resolve the issue. What appears to happen on some mobile platforms is that the object is colliding with its own feedback object, causing it to go red. My hack around this was to check for this in the objectbase OnTriggerStay method:

    // avoid treating hit with own feedback circle as a invalid pos
    if (!other.name.Contains ("Feedback")) {
    validPos = true;

    Seems to be a short term hack/fix.
     
  12. nickthegreek

    nickthegreek

    Joined:
    Jan 31, 2014
    Posts:
    12
    cdutoit thanks for the time to write down this answer. Thank you very much. I tried the solution about the memory leak and it does help indeed. Performance on my Galaxy Tab 10.1 is up. It doesn't drop below 15fps now and with some optimisation of the draw calls I think it will be even better.

    Unfortunately the second solution does not work for me. Can you please tell me if have undestood well.

    In file TriggerRegister.cs

    have this method ?

    //Called when the object hit something in trigger mode
    void OnTriggerStay2D(Collider2D other)
    {
    objectBase.SetValidPos(false);

    // avoid treating hit with own feedback circle as a invalid pos
    if (!other.name.Contains ("Feedback")) {
    objectBase.SetValidPos(true);
    }

    }

    Thanks in advance!
     
  13. cdutoit

    cdutoit

    Joined:
    Jul 20, 2013
    Posts:
    34
    @nickthegreek - glad the memory leak fix worked for you.

    My feedback circle fix is not great and we'll wait for Dreeka to respond but the possible fix is this:

    You modified the wrong file.
    In the ObjectBase.cs script, modify this method:

    void OnTriggerStay2D(Collider2D other)
    {
    if (!other.name.Contains("Feedback")) {
    validPos = true;
    }
    }

    Undo your change on the TriggerRegister method you made.
     
  14. nickthegreek

    nickthegreek

    Joined:
    Jan 31, 2014
    Posts:
    12
    Unfortunately it doesn't work in my case. Now the item stays green everywhere. It does not turn red at all so item can be placed anywhere...
     
  15. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    Same here. Looking at the code it will let you place an object anywhere as long as any colliding object does not contain 'Feedback' in its name. For example on top of another object.

    So the test should be reversed to makes sure the name *does* contain 'feedback'.

    Should it not be:
    void OnTriggerStay2D(Collider2D other)
    {
    validPos = false;
    if (other.name.Contains("Feedback")) {
    validPos = true;
    }
    {


    That way all collisions will prevent placement of the object *except* for collisions with the feedback collider.

    This code seems to work, though I only get the original error occasionally so can't be sure it's working properly.
     
  16. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    I made another tweak if anyone wants to use it. This modifies the LevelManager script to delay for 1 second before the level starts after the player presses the play button (you can adjust the delay time of course). This feels a bit more polished to me, as it gives the player a bit of time to 'brace' for the level to begin.

    Replace the EnableScene method and add a "WaitThenEnable" routine:

    public void EnableScene()
    {
    StartCoroutine ("WaitThenEnable");

    }

    IEnumerator WaitThenEnable()
    {

    // wait the delay time...
    yield return new WaitForSeconds(1);

    // code from the original Enable method
    inPlayMode = true;

    foreach (ObjectBase item in activeObjects)
    item.Enable();


    }

    This is in line with Amazing Alex, which is one of the best of this genre.
     
  17. nickthegreek

    nickthegreek

    Joined:
    Jan 31, 2014
    Posts:
    12
    Yes this works now fine! Thanks for this pumpkinszwan! I am really greatful to both of you.

    I have noticed a bug in resolution manager as well. It does not work well in my test devices. The script thinks that all screen have an aspect ratio of the ones the are predefined. It tries to calculate the aspect ratio of the device but in Android things are not that easy. In my test devices here are the results :

    Device Aspect Ratio of the device

    Nexus 10 80x47
    SIII mini 5x3 (the only one that works fine out of the box)
    Galaxy Nexus 299x180
    Pipo S1S 128x69
    Galaxy Tab 10 80x47

    You can add those aspect ratios as well in ResolutionManager as a temporary solution. But still there will be devices that this won't work. I am planning to re-write that script later on.
     
  18. cdutoit

    cdutoit

    Joined:
    Jul 20, 2013
    Posts:
    34
    @pumpkinszwan: *doh* - thanks - I had typed that from memory and you're absolutely right. Thanks for catching the inverted logic.
     
  19. DaniSanch

    DaniSanch

    Joined:
    Jan 3, 2014
    Posts:
    8
    Hi all, thanks for the help offer in this forum, someone knows that line modified to go two GoalMaker on screen, I modified lines but I'm fairly new and not come out, thanks to everyone and especially to pumpkinszwan for the double goal, Thx
     
  20. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    Do you mean to add two markers on the screen to indicate the goals? You may have to just add them manually. I haven't bothered with that yet.

    I am planning on making a script to automate the markers so the game will automatically centre them on any objects marked as goals/markers, but I haven't looked into how it currently works.
     
  21. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    I've managed to get some automatic goal/target markers working, though it could do with a bit more polish. Read the issues at the bottom of this post before deciding to implement this. Also: you MUST have my 'multiple goals' script, posted above, to use this code.

    You need to add some code to the GUIManager script and create a couple of new prefabs.

    NOTE: I'm not posting the complete script because it contains a lot of custom stuff that is specific to my modifications to the engine, and the script would break your game, so follow the steps below carefully, and post here if you get stuck

    1) Add the following variables to the top of the GUIManager script
    // these will hold our marker prefab items, which will be instantiated as needed
    public GameObject targetMarkerPrefab;
    public GameObject goalMarkerPrefab;

    // this will hold the goalslist, which will be extracted from the Overlord object, in the GoalManager script
    // this assumes you have implemented my GoalManager script, where the targets/goals are stored in an array of GoalAndTarget class
    GoalManager.GoalAndTarget[] GoalsList;

    // arrays to store the markers, which will be instantiated when required
    // the original 'markers' array will not be used for the target/goals, but will still be used to show the 'tick' when a level is won
    List<GameObject> targetMarkers;
    List<GameObject> goalMarkers;


    2) In the GUIManager script's Start() method, add the following lines *BEFORE* the 'StartCoroutine(ShowMarkers(2)));' command

    // get the level target(s) and goal(s)
    // this is coded to work with arrays (to allow for multiple targets and goals), and this will only work correctly in conjunction with a modified GoalManager script
    GoalsList = GameObject.Find ("Overlord").GetComponent<GoalManager>().GoalsList;


    // initialize our lists
    targetMarkers = new List<GameObject>();
    goalMarkers = new List<GameObject>();

    // create all the markers required and set their scale to 0,0,0 (so they are not visible until needed)

    foreach (GoalManager.GoalAndTarget targetAndGoal in GoalsList)
    {
    // create a new target marker for each target at the target's position and set the marker's scale to 0
    GameObject newTarget = Instantiate(targetMarkerPrefab, targetAndGoal.target.rigidbody2D.transform.position, targetAndGoal.target.rigidbody2D.transform.rotation) as GameObject;
    newTarget.rigidbody2D.transform.localScale = new Vector3(0,0,1);
    targetMarkers.Add(newTarget);

    // do the same for the goal marker(s)
    // note: this will create duplicates if the same goal object is used for multiple targets, but they will simply overlap and appear as one, so it shouldn't be a problem
    // there may be room for optimisation here
    // check for null goals, which are required for the balloon popping target
    if (targetAndGoal.goal)
    {
    GameObject newGoal = Instantiate(goalMarkerPrefab, targetAndGoal.goal.rigidbody2D.transform.position, targetAndGoal.goal.rigidbody2D.transform.rotation) as GameObject;
    newGoal.rigidbody2D.transform.localScale=new Vector3(0,0,1);
    goalMarkers.Add(newGoal);
    }


    3) Replace the HideMarkers method with the following code (I recommend commenting out the original to keep it handy)
    void HideMarkers()
    {
    markersVisible = false;
    StopCoroutine("ShowMarkers");


    // replacement code for the new method of showing markers
    foreach (GameObject targetMarker in targetMarkers)
    targetMarker.rigidbody2D.transform.localScale = new Vector3(0,0,1);

    foreach (GameObject goalMarker in goalMarkers)
    goalMarker.rigidbody2D.transform.localScale = new Vector3(0,0,1);
    }

    4) Replace the ShowMarkers method with the following (comment out the original again)

    IEnumerator ShowMarkers(float showTime)
    {
    markersVisible = true;
    yield return new WaitForSeconds(1);

    //Scale up the markers

    foreach (GameObject targetMarker in targetMarkers)
    StartCoroutine(ScaleObject(targetMarker.transform, Vector2.one, 0.25f, 0));


    foreach (GameObject goalMarker in goalMarkers)
    StartCoroutine(ScaleObject(goalMarker.transform, Vector2.one, 0.25f, 0));


    yield return new WaitForSeconds(showTime);

    //Scale down the markers to zero
    foreach (GameObject targetMarker in targetMarkers)
    targetMarker.transform.localScale= Vector2.zero;


    foreach (GameObject goalMarker in goalMarkers)
    goalMarker.transform.localScale= Vector2.zero;


    markersVisible = false;
    }


    5) Create 2 new prefabs from the markers in GUIManager > Markers by dragging goalMarker and targetMarker into your Prefabs folder.
    6) Add a Rigidbody2D to the 2 new prefabs, and make them kinematic, 0 mass, and 0 gravity scale (so they don't interact with the scene)
    7) Select the GUIManager and you will have two empty variables in the editor called 'Target Marker Prefab' and 'Goal Marker Prefab'. Drag your new prefabs into the appropriate slots.

    -------------------------------------------------------------------------------------------------------------
    Now your levels will automatically display markers for all goals/targets, and you don't even have to place them yourself!

    ISSUES
    This is a quick and dirty implementation. The default marker for the goal is an arrow, and this will display in the centre of the goal item, so you should change this (shouldn't be too hard). I am thinking of maybe implementing a few different types of marker to use depending on the items and their location (e.g. an arrow pointing to the right placed to the left of the goal so it points AT the goal).

    With multiple goals or targets there is no indication which goal goes with which target (only a problem if you use different goals for the targets). I will try to implement a way to get around this, such as different coloured markers for each goal/target pair.


    EDIT: New issue: If you use the 'empty target' prefab in your game you will need to add a rigidbody2D to it due to the way my code accesses the item's position (so it knows where to place the marker). Add it in the same way you add it to the other prefabs (kinematic, not mass, no gravity).

    EDIT2: Added check for a null goal in case the target is popping a balloon (which has no associated goal). Null goals are simply ignored
     
    Last edited: Mar 10, 2014
  22. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    I've got another bit of code, which I think improves the display of markers.

    I've modified the ReceiveInput method of the GUIManager script to do (re) show the goal/target markers when a level is paused and when a level is restarted from the pause menu. I think this helps the player, as it lets them pause the game to get reminded where the goals/targets are, and again if the restart the level they will again see the markers.

    The code below replaces the ReceiveInput method completely. All it really does is call the ShowMarkers coroutine when specific conditions are met. It's pretty easy to chop and change:

    public void ReceiveInput(Transform button)
    {
    if (levelState == LevelState.inChange)
    return;

    switch (button.name)
    {
    case "Play":
    if (levelState == LevelState.inPlanning)
    PlayLevel();
    else if (levelState == LevelState.inPlaying)
    {
    StopLevel();
    StartCoroutine(ShowMarkers(2));
    }
    break;

    case "Pause":
    if (levelState == LevelState.inPlanning)
    PauseLevel();
    else if (levelState == LevelState.inPause)
    UnpauseLevel();
    break;

    case "ToolboxButton":
    ToolboxManager.Instance.ButtonPressed();
    break;

    case "Restart":

    LevelManager.Instance.RestartScene();
    StartCoroutine(ShowMarkers(2));
    break;

    case "FinishRestart":

    RestartFromFinish();
    break;

    case "LevelSelect":
    Application.LoadLevel(levelPackName());
    break;

    case "NextLevel":
    if (levelNumber() < 12)
    Application.LoadLevel(nextLevel());
    break;
    }

    StartCoroutine(Animate(button, 0.1f, 0.15f));
    }
     
  23. ionbrainz

    ionbrainz

    Joined:
    Jan 13, 2014
    Posts:
    5
    Has this update for iOS and Android came out yet?
     
  24. UltraTM

    UltraTM

    Joined:
    Dec 8, 2013
    Posts:
    221
    iOs dont know but Android is working. Still waiting for the update with second level page example and so .
     
  25. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    Hey,

    Sorry for the late reply! I am having an test heavy week, and I have much to learn. Still, I know it is not fair of me to keep you waiting for soo much time. So, from now on, I am going to visit the forums every day, and I am going to answer your questions within 24 hours.

    cdutoit, nickthegreek, pumpkinszwan:
    Thanks for highlighting problems, and helping the community! I really appreciate it! :)

    ionbrainz:
    The mobile support update is out, but there is a bug in the touch controls (see above). It will be fixed in the next update.

    UltraTM:
    I will provide it as soon as possible.
     
  26. UltraTM

    UltraTM

    Joined:
    Dec 8, 2013
    Posts:
    221
    No problem Dreeka- stress in reallife and work ist still priority :)
     
  27. cdutoit

    cdutoit

    Joined:
    Jul 20, 2013
    Posts:
    34
    Happy to announce my game based on this kit is now published on both platforms.

    For those of you familiar with the kit, these are some of the major changes I made:

    First, all the components are basically pipes since that is the object of the game
    I made multiple goals
    I added a hint capability which shows text at the start of certain levels
    I added new pipe components, such as the accelerator which speeds up the ball which you need to go "up", and the multiplexer which duplicates the ball which you need when you have multiple goals.
    New components were created using playmaker, so I had to modify the code at certain points to raise playmaker events to cue off of
    I changed the level manager to start at level 1 unlocked and all the rest locked, and then they progressively unlock
    I added a "snap" function as you rotate to line it up on the horizontal and vertical
    I added music
    I added the stop/exit
    I added the sound toggle on/off
    Added Chartboost
    And then created the levels of progressing difficulty using all the pipe components I supply.

    At least that's it in a nutshell. Overall very happy with the outcome. Getting good reviews so far. One "1 star" review since the reviewer says it crashes on ios 7.1 iphone 5 and I don't have any way of testing that configuration. I suspect (hope) it is to do with a lack of memory on his device but its a shame to get 1 star after all that work. If any of you have a iphone 5 with ios 7.1 and are willing to try it for me, I'd really appreciate it. It is a free download. If there is a crash problem on that device I need to find it ASAP.

    The link to ios or android version are here on the facebook page

    https://www.facebook.com/pipesnthings

    Thanks to the community and the author of the original toolkit. Now just to go figure out how to get more downloads and positive reviews.... ;)
     
  28. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    @cdutoit

    The game looks great. I'm charging up (and dusting off!) my old Android tablet to give it a try. Do you have any plans to share the 'snap' functionality code? The pipes in the stock engine could really do with Amazing Alex style snapping. Without it pipes can be a bit fiddly.

    My own game isn't finished yet, but here's a quick video of it (currently untitled):


    I've implemented a bunch of stuff, off the top of my head:
    * multiple goals
    * new objects/prefabs: (cannon, 'spray' object (water hose that pushes items that fall within its path), trapdoor triggered by a button, popcorn box that spills popcorn kernels when it's knocked over
    * sound toggle/music/SFX
    * tweaks to some of the built-in objects (e.g. making the balloon faster)

    I still have a bunch of bugs/glitches to fix (you can see a few clearly in the video, such as the toolbox 'hiding' my goal markers), and I want to do a bunch more levels (currently have about 40, of which 12 are really simple tutorial levels).

    The game (currently untitled) will be available on Windows 8 and Windows Phone 8 soonish, with hopefully Android and iOS versions to follow.
     
  29. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    cdutoit, pumpkinszwan:
    Really good job with the kit! It is really good to see when people use our kits to create their games.
    I wish you the best of luck with your games! :)
     
  30. DaniSanch

    DaniSanch

    Joined:
    Jan 3, 2014
    Posts:
    8
    I congratulate you both for your work .......
    I'm new to Unity and as a novice programmer still ..... some tips to learn how to program in C # or Js, books, tutorials, etc ...

    Thank you very much and good luck with your work.
     
  31. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    >some tips to learn how to program in C # or Js, books,

    If you already know a little programming and want to apply that to C#, this site is fantastic:
    http://www.dotnetperls.com/

    I'm a VB programmer, and that site really helps me when I don't quite know how to translate into C#.

    I'm also learning a lot from just playing with this toolkit and modifying it for my own project.
     
  32. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    I've been getting regular crashing, which I have narrowed down to the feedback manager. The game will crash randomly when manipulating objects (e.g. placement and rotation). I can reproduce the crashing by 'spamming' the feedback/item in the game, e.g. tapping an object I'm placing quickly and repeatedly, though the crash also happens during 'normal' playing scenarios.

    The crash is happens on Windows Store and Windows Phone, but I can't replicate it on Android or in the Unity editor. The crashing gives the following error (the game minimises, clicking Ignore will actually return to the game and it will continue just fine):

    IMAGE LINK

    During debugging I have found that the crash seems to be caused in several different ways. It seems that any time the transform is modified in the script there is the potential for the crash, e.g.:

    I
    I've tried placing 'try...catch' around the problem lines, but that doesn't help. When debugging on the PC the crashes still happen, and on the tablet the app just force closes without displaying the error.

    The only clue to the problem is that the feedback circle tends to pause at a certain diameter before the crashing, as if it's stuck or the change in size has been cancelled. This doesn't always happen though.

    Sometimes the crash comes when I hit the Play button to start the scene moving...though this may be a different crash altogether.

    I can usually play 10 or more levels without an issue, but then I'll get the crash, so maybe certain values or timing could be the issue.

    I'm not 100% sure, but it may be happening most often on specific items: trampoline and bendy pipe, but it could just be that these two items need to be placed and rotated more accurately than most in the game, thus being manipulated more.


    Steps to reproduce in the 'out of box' 2D Puzzle Kit:
    [must be on Windows 8 or above, I'm on 8.1]
    1) Untick 'use touch' to control with mouse
    2) Build a Windows Store version
    3) Open the solution in Visual Studio, set to debug, x86, and then star debugging
    4) Drag an item from the toolbox onto the play area and click it with the mouse repeatedly...this eventually causes the crash.
    NOTE: A curved pipe seems to trigger the crash more quickly than a shelf (in my game it's also trampolines, which I modified to rotate).

    You can see the error text in the Output window.

    Any ideas?



    EDIT:
    I am pretty certain I've narrowed it down to the rescaling of the feedback object.

    I've changed the code slightly to skip the scaling on Windows and Windows Phone (using conditional compiling):
    Code (csharp):
    1.  
    2.         while (t < 1.0f)
    3.         {
    4.      
    5.             t += Time.deltaTime * rate;
    6.          
    7.         }
    8.      
    9.   obj.transform.localScale = Vector3.Lerp(startScale, endScale, t); //this is the line causing crashes!
    10.          yield return new WaitForEndOfFrame();
    11.  

    But this is just a workaround. I lose the shrinking/growing animation, but it seems to avoid the crashing.

    Is there a different way to animate the feedback in and out? I think the Lerp is the problem, which would explain why it's not giving me a breakpoint in my C# (from what little I understand about Lerp, which is almost nothing!).


    I also noticed that when added some debug code, the gameplay was slowed down and I couldn't make it crash...making me think maybe there is something to do with timing. Perhaps when tapping too quickly the previous action is not completed, and that causes the crash? Is there a way to reduce the speed of updates or incorporate a check to make sure the last action is complete before starting another?
     
    Last edited: Mar 31, 2014
  33. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    pumpkinszwan:
    This is a strange issue. I don't think that the line you have commented out is the souce of the issue. Something is probably happening while the element rotates. I cant access to windows 8 at the moment, so I cant test it out myself, but you should investigate in the InputManager's rotation related functions (PrepareToRotate, RotateItem, FinaliseRotation).

    Timing cant be an issue. It is managed entirely by Unity, and a new update is not called, until everything from the previous update is finished.

    You should also try to run it in 32 bit mode, because it is possible that running the kit in 64bit causes the issue.
     
    Last edited: Mar 31, 2014
  34. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    Dreeka,

    Thanks. I actually just rewrote my post with new info before I noticed your reply.

    From what little I know about stack traces the crash is actually caused by Unity's own DLL.

    I'll continue to test on my devices by simply playing my game over and over, but I'm now quite sure it's the scaling of the feedback item rather than the rotating.

    I can also add that I've tried reproducing the error on cdutoit's Android game 'Pipes n Things' without any luck. So it seems to be Windows specific (or at least specific to my devices).


    I run Unity in 32-bit, and my game is testing in 32-bit x86 and ARM (tablet). Unity apparently doesn't support 64-bit for Windows Store, so that's not the issue.

    EDIT: Rotation is ALSO causing the crash, so it's either 2 separate issues or the same issue affecting the rotation and resizing of the feedback item.

    It seems stable with both rotation and scaling commented out (the object doesn't rotate or scale, of course, so it's just a workaround for now).
     
    Last edited: Mar 31, 2014
  35. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    I have found a weird issue that may be a cause of the crashes I've described above.

    The scaling method used in the toolkit has a flaw... if I tap a button with the 'bouncy' effect and then tap it again while it's still in the 'growing' phase of its animation, the animation starts again, but now acts as if the larger size was it's original size... so if I press the buttons very quickly they grow in size! I think rather than scaling between [small size] and [normal size] the method just scales by a certain amount, so if the button is pressed at any time during an animation cycle it will grow/shrink the wrong amount.

    I'm not sure if this is Windows only at this stage. If anyone can test on other platforms I'd appreciate it. I have added my own buttons for, e.g. turning music off and on and used the same animation that the default buttons use... the problem I get only occurs when the button tap doesn't trigger a new scene load (because the first press effectively stops you from pressing again if a new scene is loaded).

    So I wonder if this same issue is what causes the feedback to crash when tapped too rapidly or at the wrong time. Disabling the scaling certainly prevents the crashing. If this behaviour can't be reproduced on other platforms it may be evidence that there is some issue specific to Windows Store/Phone that causes this and also leads to some of my crashes.


    On another note, I think I have found a solution to the crashing caused by the rotating...I rewrote the rotation algorithm to be much simpler (it just rotates by 1 every update without calculating anything)...I have so far not managed to force a crash with this method, but need to test more.
     
  36. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    For anyone using this toolkit for Windows Store and/or Phone and gets the above-mentioned crashes, here's my half-fix, half workaround. This appears to be a Unity and/or Windows bug, NOT a bug in this toolkit.

    My fix replaces the feedback rotation with a much simpler method that seems to work exactly the same as the in-built one (I have not noticed any negative side effects myself), and disables the scaling of the feedback (haven't figured out a way to replace that with a method that performs the same task without crashing).

    Feedback rotation fix:
    1) Edit the Update method in the FeedbackManager script like so:
    Code (csharp):
    1.  
    2. void Update ()
    3.     {
    4.         if (target)
    5.         {
    6.             UpdateTexture();
    7.             feedback.transform.position = target.GetFeedbackPos();
    8.  
    9.             // to avoid crashes on WinRT platforms
    10. #if (UNITY_METRO || UNITY_WP8)
    11.            
    12.    
    13.            
    14.      
    15.  
    16.             // the following line seems to be the crash cause on Windows platforms
    17.           //feedback.transform.Rotate(Vector3.forward * rotationSpeed * Time.deltaTime);
    18.  
    19.                
    20.              feedback.transform.Rotate(0, 0, 1);
    21.  
    22.  
    23. #else
    24.  
    25.  
    26.             feedback.transform.Rotate(Vector3.forward * rotationSpeed * Time.deltaTime);
    27. #endif
    28.        
    29. }
    30.  
    This basically replaces the rotation only on Windows Store/Windows Phone and leaves the code intact for all other platforms.


    Scaling removal
    2) In the Rescale method, comment out the following lines:
    Code (csharp):
    1.  
    2.             // disable the scale in/out for Windows platforms as it seems to cause crashes
    3.            //obj.transform.localScale = Vector3.Lerp(startScale, endScale, t); //this is the line causing crashes!
    4.            // yield return new WaitForEndOfFrame();
    5.  
    You can of course use the same #if (UNITY_METRO || UNITY_WP8) conditional compilation block to leave the scaling intact on other platforms.

    With these two changes I have not had a crash in several days. If anyone else gets crashes similar to what I've described on other platforms I'd appreciate a comment in here to help get to the bottom of it.
     
  37. bitphaser

    bitphaser

    Joined:
    Apr 3, 2014
    Posts:
    2
    When I run the game mouse clicks do not work at all. I have not changed any settings. Am I doing something wrong?
     
  38. bitphaser

    bitphaser

    Joined:
    Apr 3, 2014
    Posts:
    2
    ok I now see that I had to uncheck "use touch" on all the input management script components
     
  39. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    pumpkinszwan:
    I am glad you have managed to find a solution to the issue. :)
    Sorry I could not help with it, but as I said, I don't have access to a windows phone.

    I will fix the button scaling issue in the next build.

    bitphaser:
    Yes, you have to uncheck "use touch" to use a mouse in game.
     
  40. wmessier

    wmessier

    Joined:
    Apr 9, 2014
    Posts:
    3
    I've trying get the 2D Physics Puzzle Kit to work - no luck - After 10 days so far no response to my request for help with this kit - I'm on a deadline to get this game out - maybe I'll put a review on their product asset page so others can decide if no support is worth the purchase of the kit

    My email is (aj@callsoho.com)
     
  41. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    Hey,

    I have received you first, and only email at 2014. 04. 08. 20:45. Still, sorry I was not able to response immediately!

    To make the kit work with mouse input, you have to uncheck "Use Touch" in the Input Manager (it is attached to the overlord gameobject).
     
  42. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214

    Doing some testing on my game I found that this solution absolutely works for a performance bug I had. RAM usage on Windows RT was rising constantly, (getting close to 300MB after about 15 levels). Adding the above line stops that (and the resulting performance drop).


    I've also created a method that makes the feedback much more robust. It requires a lot of changes to the ObjectBase script, so be careful if you try this code yourself.


    How it works:
    1) everything that collides with the item being dragged/placed gets added to a list
    2) I check in Update() if any items in that list should prevent the placement of an item (e.g. colliding with a shelf or the floor)
    3) Clear the objects so that only objects still colliding get re-added in the next frame*

    This also allows me to ignore the collision with the feedback itself as well as the toolbox (which in the current implementation actually prevents item placement). This method seems less prone to issues in my testing so far.

    * Logically, items should be removed from the list in the CollsionExit, but I have found that this is for some reason unreliable. Simply removing the objects and re-adding them every frame shouldn't affect performance


    1) Add some variables to the ObjectBase script:
    Code (csharp):
    1.  
    2.  bool BeingDragged = false;                              // is this item currently being placed in 'setup' mode
    3.  
    4.     List<Collider2D> objects = new List<Collider2D>();           // list of objects this is colliding with at any given time (to check if the item can be placed on the screen)
    5.  
    2) Replace the OnTriggerStay2D method with the following:
    Code (csharp):
    1.  
    2.     void OnTriggerStay2D(Collider2D other)
    3.     {
    4.         if (!BeingDragged)
    5.             return;
    6.  
    7.         // when this collides with an item the item is added to a list
    8.         // every frame the list is checked for 'illegal' collisions
    9.         // items are removed when they exit the collision
    10.  
    11.  
    12.         if (!objects.Contains(other)  !other.name.Contains("backgroundCap")  !other.name.Contains("Feedback")) // do not include items that we are allowed to place this object 'on top' of, such as it's own feedback circle. Also don't re-add items already in this list.
    13.         {
    14.           //  Debug.Log("Added " + other.name + " to " + this.name);
    15.             objects.Add(other);
    16.          
    17.         }
    18.        
    19.     }
    20.  
    NOTE: this currently doesn't let the player place an item 'behind' the UI buttons (e.g. the Play button). These could easily be added to the list of items that don't block placement

    3) Add this short FixedUpdate() method:
    Code (csharp):
    1.  
    2. void FixedUpdate()
    3.     {
    4.         if (BeingDragged) // not relevant if the item is not being dragged/placed currently
    5.             {
    6.                 CheckValid(); // check if the current position is valid
    7.                 objects.Clear(); // clear all items that may be currently colliding with the item being dragged. they will be re-added in the next frame if still colliding
    8.             }
    9.     }
    10.  

    4) Add the method to check if the item's current position is a valid place to drop it:
    Code (csharp):
    1.  
    2.  void CheckValid()
    3.     {
    4.         bool valid = true; // default to true, then revert to false if any objects are currently touching the one being placed
    5.  
    6.         if (objects.Count > 0)
    7.         {
    8.             //// since we only add objects that prevent placing the item to the objects list, if objects is not empty the player can't put the item in the current position
    9.  
    10.             valid = false;
    11.         }
    12.  
    13.         validPos = valid;
    14.     }
    15.  
    5) Add the following lines in the DragMode() method (anywhere will do):
    Code (csharp):
    1.  
    2.         // clear any collisions and set the object to BeingDragged
    3.         objects.Clear();
    4.         BeingDragged = true;
    5.  
    6) Add this line to the Dropped() *and* RotationEnded methods:
    Code (csharp):
    1.  
    2. BeingDragged = false;
    3.  


    That method is working great for me. I have also used a similar method to implement a 'spraying water' object that affects items that come into contact with its spray area. It should also provide a starting point for a moving shelf or similar object that needs to affect items in contact with it.
     
  43. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    Thanks for you efforts, you are really cool! :)
     
  44. DaniSanch

    DaniSanch

    Joined:
    Jan 3, 2014
    Posts:
    8
    Pumpkinszwan thank you very much for sharing these important changes to WP8 .

    I have a question about an error that is currently being given to debug the app with visual studio in RCcar script , If I compile the app , I can start on the phone and it works pretty well but in particular the car does not work and when debugging for WP8 get an error on line 53 RcCar Script.

    The problem is generates for this:

    Exception: Common Language Runtime detected an invalid program.
    Type: System.InvalidProgramException
    Module: UnityEngine
    InnerException: <Do Data>
    AdditionalInfo: <Do Data>
    at UnityEngine.HingeJoint2D.set_motor (JointMotor2D value)
    at RcCar.FixedUpdate ()
    at RcCar.UnityFastinvoke_FixedUpdate ()

    This is the line that generates the error script
    . wheels[1].motor = motor;



    Someone knows why this particular part of the script does not work with WP8??
     
    Last edited: May 6, 2014
  45. masha

    masha

    Joined:
    Aug 20, 2012
    Posts:
    8
    For those of you experiencing the issue with the object position never being valid (red circle), a non programming solution is to change the Feedback's layer to default.

    Then, in the Physics2D settings (Edit > Project Settings > Physics 2D) un-tick the check box connecting the GameObject layer to the default layer.
    If you don't want objects colliding with GUI elements and the toolbox, go ahead and un-tick the connection between GUI and GameObject as well.

    $Physics2DSettings.jpg

    The downside to this approach is that the level colliders (Buttom, Left and Right), all of which are on the default layer, stop working correctly and objects can be placed offscreen. I'd recommend creating another layer, Colliders and having it interact with the GameObject Layer.

    You also need to add the default layer to the InputManager mask (located in the Overlord object). This is to allow the Feedback object to receive touches and rotate your gameObject. Once gain, you can always create another layer specially for the feedback if you don't want to add the default layer to the input manager.

    $Physics2DSettings2.jpg
     
    Last edited: May 21, 2014
  46. cdutoit

    cdutoit

    Joined:
    Jul 20, 2013
    Posts:
    34
    @pumpkinswanz - glad my solution helped you too. Have you published your app yet...your video preview looked really cool. My app is out - I got one or two complaints on the play store about it crashing but it was impossible to track down. Problem with android are the thousand different device types so it could be something completely unrelated.

    I haven't started a new app yet. I have my eye on Dreeka's Infinite Runner Toolkit for my next project :)

    I don't mean to sound like I'm spamming, but I'd like to offer you a free Starter package on my new app review service. So when you publish your app you can instantly get some downloads and reviews from REAL people. Not some faked IP's or anything. Yeah...I've been busy :) This is what happens when you take a break from Unity coding :) Anyway the service is appiness.io - check it out. It will help me test out the platform and you get some instant downloads and reviews. Email me at support@appiness.io if you're interested, and no worries if not!
     
  47. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    >. Have you published your app yet

    I'm close to publishing...but still have a few things to sort out.

    >I'd like to offer you a free Starter package on my new app review service.


    Looks cool, but I don't think I'll be publishing to Android or iOS in the near future.
     
  48. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    Update 1.02 has been submitted to the asset store!

    Changelist:
    o Improved touch controls
    o New resolution manager
    o Bug fixes
     
  49. pumpkinszwan

    pumpkinszwan

    Joined:
    Feb 6, 2014
    Posts:
    214
    > Update 1.02 has been submitted to the asset store!

    Great news!

    Also Unity 4.5 has changed 2D physics a LOT, totally altering my game.

    I have two fixes/workarounds for anyone wanting to upgrade to Unity 4.5:

    Workaround for 'red feedback circle when rotating with Unity 4.5'

    In the FeedbackManager script, RotateWith method, comment out:
    Code (csharp):
    1.    // feedback.transform.parent = item;
    I think Unity 4.5 considers collisions with a child item to be a collision with a parent, and therefore when the feedback circle touches something (even when the actual item is not touching) it causes the location to be invalid.

    The drawback of this workaround is that the feedback circle doesn't rotate when you are actually rotating the item. There is probably an easy fix that I can't think of to retain the rotating.

    Workaround for altered physics in Unity 4.5
    A property on Rigidbody2D called "inertia" is calculated differently and will cause all 2D physics objects to have different qualities (affected by gravity differently mainly) from Unity 4.3. To fix this, you need to set the inertia property for all physics objects in the game to an appropriate value. I am finding that 0.5 works for most things in my game (I think the default is 1 in Unity 4.5). I have added a new public float to the PhysicsObject script called 'Inertia' (so I can set it in the inspector), and then added the following line to the PhysicsObject script in the Enable method:
    Code (csharp):
    1. this.rigidbody2D.inertia = inertia;
    Set your prefabs to the correct value and your game should work more or less the same as in Unity 4.3. You will need to fiddle with the numbers a bit to get everything perfect, but the bug fixes in 4.5 should make it worth the effort (e.g. I now don't see any inconsistent physics if I run the same level twice without changing anything).
     
    Last edited: May 28, 2014
  50. Dreeka

    Dreeka

    Joined:
    Jul 15, 2010
    Posts:
    507
    The kit in on sale this weekend!
    Now you can buy this toolkit for only $25! Dont miss it!
    $physics_sale_banner.png

    We would really appreciate if you could take your time and rate the product on the asset store, if you have bought it!
     
    Last edited: May 31, 2014