Announcement

Collapse
No announcement yet.

Trouble with adding to array in different blueprint

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

    Trouble with adding to array in different blueprint

    Hey guys!

    I've been working on creating a randomly spawning hex tile map. I've gotten quite a lot of progress done the last few days with actually spawning the tiles into a map the way I want. I'm running into an issue though and so far my google-fu has let me down. I want to store a list of all the tiles in an array in a blueprint we can call Tiles. The tiles themselves are being spawned in a different blueprint we can call MapCreator.

    I have read through the documentation on Blueprint Communication and casting but something must not be clicking. I saw how Unreal explains it using direct communication and setting which blueprint you are talking about by default. My issue is neither of these blueprints exist inside of the level. I spawn both of these blueprints when the game starts. Each time I've tried to cast to the Tiles to add to the array I always end up getting cast failed. I believe the way to go about this would be with casting, I just don't believe I'm doing casting right.

    I'm currently at work right now or I would provide screenshots of how I'm doing things. I feel like this shouldn't be that hard to do and I'm missing something easy. I plan on giving it another go when I get home tonight and hopefully making some progress. Any help would be greatly appreciated!

    #2
    Hello,
    different ideas :
    Create your array in your first blueprint and do a custom event done on spawn to get the array.
    Create and save your array in a third blueprint : then use array from it (with cast to or with what i explain below) or send it to second blueprint via custom event or function.
    You may not need to have your array in second blueprint too : Create your array in first blueprint, and in second, create a variable of the first blueprint type and you set it (get all actors / get) on event begin play) From this node, you have access to your array.
    Maybe other ideas...

    Comment


      #3
      Hey there,

      " I spawn both of these blueprints". That is the way you are going . The Blueprint/Class which Spawn your blueprints are the ones which are holding the spawned references.

      When you spawn something, your node has an output pin, take it and save it in a variable. The "Spawner" will now be the controller of your spawned instance, and f.e. your spawned instance has the array you want to get inside somewhere else.

      Before i move on, i want to know if your "Spawner" spawns both of your bp´s ?
      Live long and prosper.

      Comment


        #4
        lol Fen good timing^^
        Live long and prosper.

        Comment


          #5
          Thanks for the advice guys!

          I got caught up with work last night and did not get a chance to do any game development. I had tried to set the variables from where I spawned them but think I might have done something incorrect. I think I have a better idea of what to try now so hopefully I can knock this out and move on to something else tonight! Appreciate it, will let ya know how it goes!

          Comment


            #6
            Don't hesitate to share blueprints if you have a trouble. We'll help you to solve it if we can.

            Comment


              #7
              Alright so I've gotten further but still run into an error that I'm having trouble figuring out.

              For testing and trying to solve this error right now I have a tile already in the level so the array that contains the list of tile from default has 1 item and is not empty. What I'm trying to do is pick a random tile from our list of tiles, then pick a random side of that tile and spawn a new tile if a tile doesn't exist there already. I'm running into an error on my function that picks a tile. So far it will spawn all 7 tiles I tell it to but I keep getting this error message:

              Click image for larger version

Name:	SeizeError.PNG
Views:	1
Size:	15.5 KB
ID:	1066125

              I also have some tiles that will still overlap. The way I've been doing it is by comparing the new location with the locations of the tiles already in the list. I have been unable to get past this error so far though because even making sure my array is not empty by default and using prints to make sure that I wasn't trying to access something that didn't exist in the array...everything appears correct to me.

              Click image for larger version

Name:	RandomTile.PNG
Views:	1
Size:	127.3 KB
ID:	1066126

              Any help would be appreciated!

              Comment


                #8
                Wow 30 seconds after I hit submit I figured it out. So please feel free to disregard! I do appreciate the help though guys. Just in case anyone is curious it had nothing to do with the blueprint that I posted above.

                Click image for larger version

Name:	Derp.PNG
Views:	1
Size:	72.9 KB
ID:	1066127

                I forgot to attach my array to the foreach loop in the next function that gets called....so maybe I need a break

                Comment


                  #9
                  Alright so I've finally narrowed down my problem.

                  This is basically what I've been fighting the whole time I just thought I was doing casting wrong. After much use of print strings I found out that wasn't even my original problem, I was doing that correct from the start of this thread :/

                  My issue comes down to comparing vectors. My function "Check if tile already exists" takes a vector location where we want to spawn our next tile. I then loop through my list of current tiles and compare their location with the location I want to spawn my next tile. If there already exists a tile there I do not want to spawn another on top of it. I set up print strings to show me exactly what was happening with each value and narrowed it down to when I compare the vectors no matter what happens it always comes out false. I've tried changing the tolerance to 1000 different numbers both big and small. Tried to come up with an alternate way to do this. But at the moment I'm getting frustrated and think I must be missing something obvious.

                  Here is my function:

                  Click image for larger version

Name:	CheckTile.PNG
Views:	1
Size:	169.9 KB
ID:	1066130
                  It compares the two vectors and if it finds one that matches "New Tile Location" it's supposed to break and tell us we can't use that spot.

                  Here is my debug log of strings:

                  Click image for larger version

Name:	debuglog.PNG
Views:	1
Size:	49.5 KB
ID:	1066131
                  It was set to print: New Tile Location - Selected Tile from Tile list Display name - Selected Tile's Location - Result of are they equal

                  As you can see the one highlighted yellow they can be exact same with no tolerance/margin of difference and it still returns false.

                  Any ideas on what I'm doing wrong, if I'm overlooking something?

                  Comment


                    #10
                    I just did a try and it works for me. Only case it was not working is when i had linked an empty "get actor location" as new location and it shown a 0.0.0 the none value when reference is empty. Maybe your issue.
                    If you don't need to know which tile is concerned you can replace your system by a "contains" (you do an array of the locations of your tiles instead of tiles) and from it : "contains" : true : loc is ever used, false, it is ok.
                    Click image for larger version

Name:	vectors.jpg
Views:	1
Size:	58.4 KB
ID:	1066135

                    edit : the "contains" :
                    Click image for larger version

Name:	vectors2.jpg
Views:	1
Size:	55.7 KB
ID:	1066136
                    Last edited by Fen; 02-07-2015, 04:25 PM.

                    Comment


                      #11
                      Thank you very much for your time Fen. I think I may have gotten my problems figured out now!

                      During my troubleshooting I had been messing with all my blueprints and after much banging my head against my desk I figured out that I had passed over my check that returned from this function and spawned the tile regardless of the answer from checking. I believe this is because I had put it into an infinite loop at one point then I never remembered to re-attach it.

                      Then I ran into where it would place the new tile but the location would be 40, 42.02,0 compared to 40, 42, 0 and it would place the tile. So I changed the tolerance to 10 and now it seems to be spawning without issues!

                      I was unaware of the contains method that's actually very neat! Thanks again for your help, I'm going to keep on chugging along and see what else I can get done now!

                      Comment


                        #12
                        Originally posted by Snackmix View Post
                        Alright so I've gotten further but still run into an error that I'm having trouble figuring out.

                        For testing and trying to solve this error right now I have a tile already in the level so the array that contains the list of tile from default has 1 item and is not empty. What I'm trying to do is pick a random tile from our list of tiles, then pick a random side of that tile and spawn a new tile if a tile doesn't exist there already. I'm running into an error on my function that picks a tile. So far it will spawn all 7 tiles I tell it to but I keep getting this error message:

                        [ATTACH=CONFIG]24766[/ATTACH]

                        I also have some tiles that will still overlap. The way I've been doing it is by comparing the new location with the locations of the tiles already in the list. I have been unable to get past this error so far though because even making sure my array is not empty by default and using prints to make sure that I wasn't trying to access something that didn't exist in the array...everything appears correct to me.

                        [ATTACH=CONFIG]24767[/ATTACH]

                        Any help would be appreciated!
                        This is just a small tip to tidy up something but the array node "last index" is the equivalent of "length -1".. it's not going to change your functionality but just makes it a bit tidier
                        Also there is a "get actor location" node which would be tidier than getting the transform and stripping the location out of it! furthermore, you can do an implicit case from transform to location and it does that for you

                        Comment


                          #13
                          hey there,

                          so i see 2 things which are bothering me.

                          First: in your "Check if tile already exist".
                          The boolean "Can Place Tile" is this a local variable or do you set it up as a blueprint wide variable?
                          just to give you the advice, make sure that this variable is trueorfalse when you call this function.
                          So before you do the LoopWithBreak Set Can Place Tile to trueorfalse, this wont affect your loop since you set this variable each loop anyways. I just want you to know
                          which initial status your bool would have, and in this purpose set it up as a local variable, i you havnt that is.

                          Second is:
                          Youre comparing 2 Locations with each other. I assume the xyz values inside are floats. However i dont know if the float you set in the cmp with (.00000000) will only checks up to this decimal range.
                          However, however, it is a very bad habit to compare two decimals (double, float etc.) whether they are equal. Why? Because your computer isnt able to present decimal values in a reliable way. There may be differences
                          and when they occur your code is broken and work in a way you dont want it to... aka you have a bug!

                          A thing i would test is adding a breakpoint on your return node of the Pick Random Tile and check the array if there is no null content inside. You can check that out when you add the breakpoint, hit play, do what needs to be done to fire that function. And then move your mouse over the Arrays return node.

                          regards


                          edit: i dont see the way you fill your Tile Manager with information, could you provide this?
                          Last edited by Wallhalla; 02-08-2015, 06:14 AM.
                          Live long and prosper.

                          Comment


                            #14
                            Thanks Rodstone for "last index" remainder. I use to forget it (as flip flop gate and others huhuhu)

                            Comment


                              #15
                              Thanks Rodstone! I was unaware of last index as I haven't dove through all the documentation but that's useful to know. I love tidying my code up! I do know, and use quite a bit, get actor location...I'm not sure why I didn't here but thanks again :P

                              Wallhalla I had originally set up "Can Place Tile" as a blueprint wide variable but have since changed that to make it local to that function and just pass the answer on. I have actually gotten everything working quite well now although there is one bug and that actually revolves around the decimals. I was thinking of changing my model size (because it's a placeholder I through together in 2 minutes) to see if getting that fixed would change everything.

                              I wanted to switch and use an array of my tiles vector locations instead when checking to spawn tiles using the array contains functions. This works much faster and looks much cleaner than the for each loop I was using before. The only issue I run into is that it spawns the tiles in the same location because the tiles will be off by a very small amount. I was thinking that changing my model size to something that would make it end in an even number after all the math might prevent it from moving this tiny bit (usually ~.002 off from where another tile would be).

                              Comparing the 2 using the foreach loop works fine because of the tolerance when comparing the two vectors. The only downside of this was when I wanted to create 150+ tiles UE4 would start to complain about an infinite loop because it was taking so long. I was able to spawn 500 tiles almost instantly using the contains method instead. This did cause me to have an issue with the tiles over lapping still since I can't add a tolerance to check if something is actually .0002 off with contains.

                              How would you go about checking if there is already a tile in a location without comparing their vector locations?

                              Also the information for Tile Manager is being populated correctly I'm no longer having issues with adding them to the array (and kind of wasn't in the first place.) I would show you a screen shot but I'm currently at work sorry.

                              Thanks!

                              Comment

                              Working...
                              X