Announcement

Collapse
No announcement yet.

Need Help With Accessing Specific Instance of Actor Blueprint

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

    Need Help With Accessing Specific Instance of Actor Blueprint

    Hello!

    I am currently working on an idle game (Cookie Clicker, Clicker Heroes, etc) in UE4 to try and practice working in Blueprint more.

    My game is set up as a war game, where there are many different territories you can click on to subtract their health. They passively heal as well. Eventually you will be able to allocate units to different territories to increase damage per second in that territory (but that's not the problem I'm having, just providing context because this problem will apply later). The territories are all instances of the same "Territory" blueprint, copied and pasted next to each other. Right now I'm trying to set it so that when you hover over a territory and press "U", it upgrades that specific territory and it starts taking damage per tick.

    I currently have it set so that when the cursor is over the Territory actor, it sets a Boolean "IsCursorOver" to true, and it toggles the visibility of the "Upgrade?" text component. This works fine, as "Upgrade?" is toggled on when the cursor is over the actor.

    When the "U" key is pressed, it tests if the cursor is over, and if it is, then it sets another Boolean "Upgraded" to true. I only want to upgrade that one instance.

    Every tick, it tests if the actor is upgraded, and if so, it takes damage.

    Currently, the upgrade is only working on the last instance of the blueprint. There are 30 Territories total, and pressing "U" on Territory30 upgrades it. It does not work on any other instance, instead returning false for "IsCursorOver" when "U" is pressed. Territory 30 is the only actor where the upgrade actually works.

    Could anyone help me figure out how to affect a specific instance of an actor?

    Here are some screenshots to show the blueprint I have created:

    Click image for larger version

Name:	ClickGameBlueprints4.png
Views:	1
Size:	666.0 KB
ID:	1144845

    Click image for larger version

Name:	ClickGameBlueprints1.png
Views:	1
Size:	281.6 KB
ID:	1144842

    Click image for larger version

Name:	ClickGameBlueprints2.png
Views:	1
Size:	232.0 KB
ID:	1144843

    The above picture leads into the one below.

    Click image for larger version

Name:	ClickGameBlueprints3.png
Views:	1
Size:	199.2 KB
ID:	1144844

    #2
    Hello,
    Create a variable with your blueprint as type. When begin cursor over, set this variable with your hovered blueprint, and set your variable empty when you end cursor over. Set a space of 1 or 2 between each actor in level.
    On click, check if variable is empty (branch) if yes do nothing, else do your event using your variable.
    Last edited by Fen; 02-27-2015, 07:10 AM.

    Comment


      #3
      So I create an object variable referencing itself inside the territory blueprint?
      How do I set an object variable to empty? I'm not sure I completely understand.

      Comment


        #4
        This was supposed in level blueprint, but i realise it needs modifications. And it would not be needed. How do you set your actors in your level ? Set in level, spawned ?

        Comment


          #5
          The actors are just set in the level. Although if spawning them helps with this problem, it shouldn't be a problem setting up a spawn loop. I don't think doing that would mess with any of the blueprints I've already created.
          The cursor over event is contained in the blueprint of the territories, and not the level blueprint. Do you think moving that event to the level blueprint would be better? Thanks for the help!
          Last edited by InnovateTheWorld; 02-27-2015, 03:21 PM.

          Comment


            #6
            So you have set in level 30 (or any) territory1 blueprints ? Weird thing is that each click would refer to itself not the last. Are they all this blueprint ?

            Edit : interest of spawning is that you can add whole system without have to do it manually. If we don't find a solution, i'll show way a way to do it via level blueprint (or master blueprint in fact which is easier)

            Edit 2 : If you have created 30 blueprints, then here is the trouble. You have to use the same 30 times to have it working. And if you need to differenciate them at a moment, you just ahve to add an integer and set a number for each actor. You check the number to know which actor.
            Last edited by Fen; 02-27-2015, 03:30 PM.

            Comment


              #7
              Yes I set in 30 of the Territory1 blueprints. And actually you're right about that, each click only registers on that one blueprint that I clicked
              They're all the same blueprint.
              The problem is when I press the "U" button (which all of them listen for, of course), each of them should be listening for "IsCursorOver", and upgrade itself if IsCursorOver is true.

              So are you saying I would create a for each loop, and assign them each to a number in an integer variable? That makes sense, but how do I set it so that when I press U, it only upgrades the territory with that particular number assigned to it?

              Comment


                #8
                Just found the trouble : event U is in Territory blueprint. It can't fire in all. Then it fires in last one. You need to set your event in level blueprint.

                In level blueprint, you create a variable with "territory" type. You replace your "on click" and your event "u" by custom events and do it in level blueprint. This would work (but 1 am here, just did it, not tried. If trouble, i'll see tomorrow.
                Click image for larger version

Name:	idle.jpg
Views:	1
Size:	91.7 KB
ID:	1067377

                Edit : replace left mouse button, by your input action.

                Edit 2 : Compile territory to find custom events in level blueprint and use the blue output to find them.
                Last edited by Fen; 02-28-2015, 08:48 PM.

                Comment


                  #9
                  Awesome, thank you so much!
                  I was able to figure it out in a different way, but your way makes a lot of sense to me. I'll have to try it out and see if that works better for what I want.
                  Here is the different solution I found, in case anyone is interested:
                  Click image for larger version

Name:	UpgradeBlueprint.png
Views:	1
Size:	109.3 KB
ID:	1067769

                  Also, if I had any other questions involving this project, would it be better for me to make a new thread, or to ask them in here?

                  Comment


                    #10
                    It works ! So cool ^^

                    "Get all actors" is easy and fast, if you haven't a lot of actors and don't call it too much, it is really fair, but if you have lots of actor or use it a lot, you'll save ressources by setting and using variable.

                    If your next questions are directly related to this one, you'd better use the same thread, but if this a different subject, even in same project, don't hesitate to open a new thread.
                    Try to not open a lot of threads and wait from one question to another. And do not bump before 4 or 5 days. (All of those in your interest ^^)

                    And : don't hesitate to hunt by yourself. This is the funniest part of trouble ^^

                    Comment

                    Working...
                    X