Announcement

Collapse
No announcement yet.

why is my blueprint not adding value?

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

    why is my blueprint not adding value?

    So I have the exact same setup to count how many objects I create and that works great, but when I try do add up how many objects gets destroyed the INTvaraible won't add it just repeat (print text) 1.
    Click image for larger version

Name:	Screen Shot 2015-04-05 at 18.28.02.png
Views:	1
Size:	90.8 KB
ID:	1147559

    is this cause the objects destroy and therefore it won't add?

    cheers
    /Tommie

    #2
    Looks like that "NUMofDEADChar" variable is local to wherever that Blueprint is, meaning it will always be 1.

    You need to store that variable on something that persists, not a local variable.
    check my blog - cybereality.com

    Comment


      #3
      ok, but then I have to ask why dose this work?
      Click image for larger version

Name:	Screen Shot 2015-04-05 at 19.57.19.png
Views:	1
Size:	75.1 KB
ID:	1071995

      And what do you recommend me to store the variable on?

      cheers
      /Tommie
      Last edited by testNo7; 04-05-2015, 03:32 PM.

      Comment


        #4
        I think you're misunderstanding how your variables are working. I don't know the details of your setup or any of the names of anything, so I'm going to keep this abstract and refer to your first picture as Blueprint A and the second one as Blueprint B.

        The reason your tally is not working in your Blueprint A setup is pretty simple:
        Say that you have three spawned instances of Blueprint A; and you want the tally variable to be 3 to reflect this. The problem is, although they're of the same class, and the variable name is the same, the instances don't share the same variable. They each have their own version of the variable NUMofDEADchar. When that part of the script runs in each of them, the variable goes from zero to one, as instructed. When the instance is destroyed, so is the variable. And when you spawn a new instance, it will spawn with a NUMofDEADchar value of 0, just like the others. The problem isn't that the adding doesn't work, it's that you've built your system on the assumption that the instances will all share the same variable.

        If you want this to work in the way I think you intended, you need to store that variable in a place that will persist, such as a PlayerController, GameInstance etc. The reason why your Blueprint B counts correctly is because the variable is stored in a place that persists.
        Twitter: @zerofiftyone_
        Website: zerofiftyone.net - My game development blog
        Button Frenzy store page: http://store.steampowered.com/app/454630

        Comment


          #5
          awesome, I understand now why its not working, but being fairly new to this I can't say I understand how to use the PlayerController or the GameINstance.
          All Im trying to do is count how many of my objects hits the ground, maybe I can somehow find that using collied information... the search goes on

          thank you all for all the help

          /Tomme

          Comment


            #6
            If you're still having trouble with this, I can give you a quick example. I'm short on time at the moment, but I can help you out once I get off work.
            Twitter: @zerofiftyone_
            Website: zerofiftyone.net - My game development blog
            Button Frenzy store page: http://store.steampowered.com/app/454630

            Comment


              #7
              that would be awesome, and thank you.... Im new to most of this but eager to learn )

              Maybe its a better way altogether to solve this..... my goal is to subtract the objects that die off the total objects created...

              cheers
              /Tommie

              Comment


                #8
                Okay, so here's a simple method for handling tallies.

                For my example, we're storing the tally integer variable in the PlayerController blueprint; you can store it in any Blueprint you want as long as it's something that will exist throughout the entire game session without being destroyed. Depending on your purposes you might prefer to place this in your GameState or GameInstance BPs, but whichever you decide the process is the same. Anyway, start by making your tally variables and setting up custom events to increment them. For my example, I have an enemy spawner blueprint and an enemy blueprint; and I want to keep a tally of how many enemies have been spawned from the spawner and how many have been killed.

                Click image for larger version

Name:	32673853f4.png
Views:	1
Size:	92.2 KB
ID:	1072114


                In the spawner BP, we use a simple cast to the PlayerController to remotely trigger the event we set up earlier. This will make our tally tick up by one, which is what we want.

                Click image for larger version

Name:	ae03f734ac.png
Views:	1
Size:	133.5 KB
ID:	1072115


                In the enemy BP, we do pretty much the same thing, but we trigger the other custom event instead.

                Click image for larger version

Name:	e3bcc0af1d.png
Views:	1
Size:	199.3 KB
ID:	1072116


                And that's all there is to it! Your tally variables are all stored in one place for convenience, and avoids the problem you were having earlier. I hope this is helpful!
                Twitter: @zerofiftyone_
                Website: zerofiftyone.net - My game development blog
                Button Frenzy store page: http://store.steampowered.com/app/454630

                Comment


                  #9
                  absolutely phenomenal, love it and THANK you so much. I hope to get better at this and help others like you helped me..

                  cheers
                  /Tommie
                  www.pigbelly.com

                  Comment


                    #10
                    That's great to hear! Good luck with your project and with learning UE.
                    Twitter: @zerofiftyone_
                    Website: zerofiftyone.net - My game development blog
                    Button Frenzy store page: http://store.steampowered.com/app/454630

                    Comment


                      #11
                      I said to much to soon )

                      If you don't mind have another look at this
                      So I did this:
                      Click image for larger version

Name:	Screen Shot 2015-04-08 at 21.24.04.png
Views:	1
Size:	140.1 KB
ID:	1072163

                      and here is the BluePrint that has the Events:
                      Click image for larger version

Name:	Screen Shot 2015-04-08 at 21.25.07.png
Views:	1
Size:	57.0 KB
ID:	1072164

                      So I get the "failed" message so I know it tries to do something, but it seems like its not triggering my SpawnEvent in the target BluePrint??
                      What are we getting from the "player controller"?

                      cheers
                      /T
                      Last edited by testNo7; 04-08-2015, 03:31 PM.

                      Comment


                        #12
                        I think the issue is that your casting setup isn't right. If you've never used casting before, here's the official documentation on it. Basically, casting is a way of testing a whether a blueprint reference is of a certain class, and more importantly, it's a way of accessing the properties of that blueprint "remotely".


                        So there are two parts to this. I think this the part that may have been tripping you up.

                        1. This is the input pin. You have to connect a BP reference to this, otherwise the cast node won't function. If you just want to use the cast node as a test to see if a BP is or isn't of a certain class, you can plug in any blueprint reference here. However, if you want to be able to access the properties and functions of the blueprint, then you have to attach something that definitely matches the class you've specified (in my example, "BP_PlayerController" and in your example "MyCar_TL"). If you attach something that doesn't match, the cast will fail; which is what you were experiencing. You need to make sure that what you're plugging into the cast is the thing you want to be controlling. I'm guessing that MyCar_TL isn't assigned as your PlayerController, so the "Get Player Controller" node is grabbing the wrong thing for your purposes. If MyCar_TL is your pawn, then you can use "Get Player Pawn" instead for example.

                        2. This is the pin in which you can perform actions acting as your casted node. You can drag off of this pin to get or set variables, change properties or trigger functions on behalf of the casted node.


                        So with all that said, the problem you were having was with the input part. You need to provide a reference to MyCar_TL if that's what you're using. The reason I recommended PlayerController, GameState and GameInstance is because it's especially easy to get references to those; there are "get" nodes for each of them.

                        Let me know how you get on with this
                        Twitter: @zerofiftyone_
                        Website: zerofiftyone.net - My game development blog
                        Button Frenzy store page: http://store.steampowered.com/app/454630

                        Comment


                          #13
                          Thank you so very much its works like charm now
                          And thank you for helping me, its very inspiring to have you guys out there helping us newbies

                          cheers
                          /Tommie

                          Comment

                          Working...
                          X