Hi, so i am very new to unreal engine but i started to mess around a bit and wanted to make an item spawner. With some help from tutorials i managed to make it work. I now have two items that can spawn on my item spawner. The problem i now have, is that i dont know how to tell my level blueprint how much hp to give the player based on what the object is that spawned. I have two objects: Health and hotdog:) I want health to give 50 hp and hotdog to give 25, but right now the item spawner just gives 50 no matter the object. Any tips?
It depends on your class structure, and what your items are, but if the Health and Hotdog items both inherit from a common HealthRestoreActor or something similar, then you can have a float variable in there, maybe called RestoredHealth, which you can then set on the other two to be different. Then when you actually restore the health, you read the value of that variable and restore the appropriate amount. Since both of them will inherit from the same parent, you can easily cast them to the parent HealthRestoreActor, and get the value of the variable.
Hey Thanks for the response, I think i understand what you mean i just don’t know how to implement it into the node tree that i am using.
This is the setup i use to give the player health, but in the tutorial that i followed the guy took Get Item Type variable from Pickup_BP(this one determines which item and name is displayed in game) to see which item is being displayed and connects it to the For Each Loop node to then use a Enum list to specify the item, but when i try that it gives the error bellow.
Hi. For this logic you do not need to use the level blueprint. However, you can use it to spawn randomly. I’d go about this like so:
-
Create an actor for the pickup, and add a sphere collision around it:
-
Right click the sphere collision and add event → On Component Begin Overlap:
-
Set it up like so:
Now if you don’t want to change your logic, before giving health to the player you can check which item is being interacted with. Out of the foreach array element, get a == and check if it equals to a specific actor, in your case Hotdog for example. Then with a branch, you can just differentiate the health to give the player.
I recommend the first way since it is a bit more beginner friendly and easier to understand/work with. Let me know if it helps.
I don’t have time to look at it today anymore but your first way does seem a bit easier so i’ll give it a try, Thanks!
It sounds like you’re using the Level Blueprint for something which it isn’t intended to do.
The Level Blueprint is intended to add small scripting behaviors to things that are intrinsically part of a particular level – put some random fish in a pond, or turn on the lights when it’s nighttime, or somesuch.
Gameplay actions should mainly come from four places:
- The GameMode. This runs on the server, and should coordinate everything that’s big and important. Spawning NPCs could potentially be put in a GameMode, but there’s a better way to do that.
- The PlayerController. Anything the player does, should go through here. If things want to “interact with the player,” they should make themselves discoverable by the player, and perhaps use some shared interface to add themselves to a list of interactables, which the UI can show to the player.
- Dedicated AActors. These can be made as prefabs, and placed to add whatever behavior you need, wherever you need it. A typical “NPC spawner,” will be an AActor subclass, and placed in the level where you want the NPCs to spawn. It would typically have configurations for how many hitpoints to give the spawned NPCs. Other kinds of gameplay AActors may include open/close doors, equippable rocket launchers, health pick-ups, treasure chests, an acid pool floor trap, and so on.
- AIControllers. These are attached to Pawns that are spawned as NPCs, and control what that particular NPC actually does.
For the use case you’re talking about, the “Health pickup,” you’d typically put this into the pickup AActors you spawn. Make the base class have a variable called “HealthAmount,” and in the on-picked-up action, give that amount to the picking-up player. So, you’d have at least two properties on this blueprint class: “Mesh” (hot dog, or health pack,) and “HealthAmount” (some floating point value.) You’d make two Blueprints off this class, which the appropriate mesh and HealthAmount properties, and then place instances of this Blueprint in the level.
Thanks for the explanation, makes everything very clear, reading the tips from you all it seems i did some things wrong from the start so i might just start from scratch in a new project and once it works copy it over to my existing world.