I am new to unreal but I have used unity for a while. I am trying to create a fairly basic game to learn how blueprints work in unity
I have 10 flags and 6 different flagpoles. I want to get a random flag and a random pole and then combine them so a player can pick up. This is an endless runner type game, so they keep spawning for the duration of the game in random locations on the platforms.
Currently, I am using an int switch to create a child flagpole and then a second int switch for the flag. They both appear as the are supposed to but I want to destroy them once picked up and so I have to currently keep track of both and destroy in sequence. It works but there has to be a better way.
Also depending on which flag is picked up it will be good or bad for the player, so I also need to keep track of that and it changes depending on your last pick up.
I don’t want to create a separate blueprint for each of the 60 combos.
I was thinking that an array of blueprints might be a solution but I have not figured out how to do that with blueprints
Maybe there is a better solution?
Thanks, This is my very first post so I may be asking this in the wrong place
You could create an enum, which is just a list that can be represented by a variable, you could just add the 60 combos to the list. To create an enum: In UE4, go to the content browser, click on New, then go to Blueprints, then Enumeration. Once you have added items to your enum list, you can create a variables who’s type is the enum name. You can do whatever you’d like with your enum, including ‘Switch on ENUMNAMEHERE’ to do different things based on the enum value. For your flag and pole, you could just set the blueprint’s mesh based on the enum value. You will probably want to get a random int, and convert that to be a random item in your enum.
This is extremely similar, at least in function, to how I am trying to get a random cave generator going. On each mesh, you will need to add an attachment socket. For example, “PoleSocket” and “FlagSocket” though:
- Create a Blueprint Function like this:
- Create two different arrays. One that has all of your poles, the other has all of the flags. Then set up something similar to this in order to spawn a pole and a flag:
- After that, use something like this in order to attach the two together:
Hopefully this gives you a general idea on how to do it fairly easily. Using a Random Stream, and an editable random stream variable will allow you to create poles/flags based on a seed value rather than completely random, which is extremely useful to test stuff. You can always randomize the seed value later on in development once everything is known working. As far as good / bad poles and flags are concerned, just do a simple branch:
If PoleName = “BadPole” or FlagName = “BadFlag” then “do bad stuff”
Looking at it a bit more closely while trying to do a quick sketchup of it, I would create 2 separate blueprints, but with the same theme of the randomization. One for poles, one for flags. From there, follow this:
You can get the both mesh indices from the arrays in order to create a “combined item” by using the attach to -> socket name.
I thought about an enum but I wasn’t sure if it would solve my problem. I thought I would still need 60 blueprints. One for each combination of flags and poles. Instead of the 16 that I need now. I am still wrapping my head around blueprint but what I have seen so far I like.
Thanks alot. I will have to research attachment sockets. it might be what I am looking for
Do you need 60 unique flags/pole is order? Or are you just concerned with a random choosing of flag and pole (accepting that there may be a duplicate selection)?
Is the good/bad based on color or pole type or just a random choosing?
If it’s all random, create a blueprint with a variable array for flags and poles. Then, each time you spawn in the blueprint, the construction script can choose the flag and pole at random.
This is what I use for creating random cars with random colors:
Just FYI, Instead of using a random int in range node, I would use a length node for the array. That way you can add any number of car meshes and car colors without having to worry about manually updating the integer number.
Thanks, the idea is everything is random. I will have to try a variable array. I can’t see your attachment - Tearl