Announcement

Collapse
No announcement yet.

Issues Removing Tower For Tower Defence Game

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Issues Removing Tower For Tower Defence Game

    I created a Tower Menu Widget for placing and removing towers. Everything functions correctly (adding and removing towers) until you choose and add a tower and close the menu.Once the menu is closed and then opened again, nothing works/functions. I have pictures and video for further review.
    Attached Files

    #2
    You always get the 0 index, try to do a ForEachLoop from that get all actors of class array and pick the tower in question instead.
    0 will always give you the first one that's found..
    FPS Game Starter Kit
    Retro Game Starter Kit
    Quiz Game Starter Kit
    Twin Stick Game Starter Kit

    Comment


      #3
      Is there an example you can show? I think I might know what you are talking about, but just in case.

      Comment


        #4
        Sorry I forgot the video link. So here it is.
        https://youtu.be/o46L86X8uso

        Comment


          #5
          I have done both of the ways that is shown below, but only one tower works. No other tower does the same thing as the first one. I have also put a remove tower button on each of the towers in the menu. Hoping it would help, but it doesn't.

          Attached Files

          Comment


            #6
            The second problem is the way you display the Tower Widget.
            To explain the problem:
            When displaying you create the widget, let's call this instance Widget A.
            Say you add a tower, you set the booleans "is machinegun loaded", "is tower loaded"
            Then you remove the widget by removing it from viewport. Instance Widget A is gone since you're not storing it in a reference.
            Now when displaying again, you create a new widget, let's call this instance Widget B.

            So instance Widget B will not have the booleans set to true, so nothing happens when you try to delete the towers.

            Comment


              #7
              Sorry, I don't understand what you are saying. Can you better explain?

              Comment


                #8
                To display the Tower Menu you create a widget and add it to viewport.
                To remove the Tower Menu, you remove the widget from viewport.
                That means that every time you display the Tower menu, it's a different instance. A new instance is going to have the default values of data (in this case, the booleans).

                So if you spawn turrets and change some data (the booleans will be true), then remove the menu and show it again, the new instance will have the default data (booleans will be set to false).

                The solution is to work with the same instance.
                To do that, you'll have to stop creating a new widget every time you want to display the menu.
                Instead, create the Tower Menu elsewhere such as begin play or construction events and save a reference to the widget.
                Then, when you want to display or hide the Tower Menu, you work with the reference instead.

                Comment

                Working...
                X