I am fairly new to Unreal and have spent the past 2,5 hours searching the web for answers to my questions, but I never found the actual solution to my problem.
Situation
I am working on a tiny interactive environment in order to learn how to use Unreal. It’s a Dwarven house which the player can explore by walking through it and grabbing items to inspect.
I have created a bunch of items and structural elements that compose the scene. And I have also set up the blueprint for grabbing items and having a message appear on screen, when grabbing an item (see attachment).
I have used the Start Kit First Person-setup to create everything thus far.
Issue
But I am unable to find a solution for displaying different, unique texts for each item that is grabbed.
Meaning that when I grab item A, I would like to have information 1 (item name), 2 (item history) and 3 (item description) displayed for item A. When switching items to B or C, I would like to change the displayed information accordingly.
In my blueprint, I already have a reference to the item that is currently picked up. I have also successfully connected a variable from my HUD-blueprint to my First Person Character-blueprint, allowing me to change it there to be displayed. So I can already tell which item is in focus right now and I can theoretically change the text on screen - but I don’t know how to reference the correct source.
I want to make these changes dependent on the item currently picked up. Which means that I want to store all 3 information types for all items somewhere that makes sense and reference them when the item is picked up so the corresponding information can be displayed on screen.
I don’t know where I can store this kind of information and how I can refer to it in my blueprints.
Any pointers are very welcome!
Attached you will find the Blueprint of my FirstPersonCharacter [based on a tutorial by Dean Ashford][1] and the blueprint of the HUD reference [based on a tutorial by Jayanam][2].
Please correct me, if I’m wrong.
You’re suggesting that I create a parent blueprint that contains three variables for the three types of text I want to display. Then I create a new blueprint as a child of that parent blueprint for each item I have in my level.
Then I reference the parent blueprint in my FirstPersonCharacter-blueprint. When picking up an item, the content of the item is displayed, because its parent blueprint allows Unreal to draw the information through the parent from the child?
I am not sure how to set that up still. I wouldn’t know where to begin.
If you’d be willing to detail the steps, I would be endlessly grateful.
So you can make a blueprint InspectableItem, which holds things like the mesh, the description, it’s history etc.
Everything in the house inherits from this blueprint and contains the relevant info.
When you pick an item up, it doesn’t have to be a sub class of InspectableItem, but you can tell this by casting ( the actual point of casting ). If it is a sub class then the cast will enable you to extract the information at the point you’ve indicated in your graph.
EDIT: In fact you don’t even need to inherit, it would be perfectly usable as the original blueprint.
Right click in the content browser and choose Blueprint, and then Actor.
Call it something like Inspectable
Edit the blueprint and a cube as a static mesh component, and add a text variable.
( Top left in green, add component and choose cube )
Compile, save and close.
If you plonk that blueprint in your level it will always look like a cube of course, that’s the default.
Part II:
So now right click on the blueprint ( in the content browser ) and choose ‘child blueprint’.
This will be an actual item, so you can call it Book, for instance.
You can edit it, change the mesh from a cube to you book mesh and type something in the text description
This item will work in your game. You carry on making children from the original blueprint, and all of them will be from the Inspecable class.
This means that when you hit an actor with your line trace, you can do a cast on that actor to see if it’s from the Inspectable class. If it is, you can then access the text, and so on.
Does that make sense? Have a go and see where you get to. If you get stuck, show me some piccies.
I also came across this vid which explains the concept:
The Cast inside the First Person Character-blueprint didn’t work at first, because I was trying to input the physics component from the Line cast. I simply took the “Hit Actor” outlet and connected it to the Cast. I repeated the cast three times for each text I wanted to update.
In my HUD_Widget, I set up a function for each text type under “content” and inside the graph editor, I cast to the First Person Character-blueprint for the Display to update it.
Not entirely sure if I could have created this more economical, but since it’s working, I am over the moon! Also, I did not know that I could enter values for variables under “Class Defaults” of a child actor… so that was a big part of not understanding how the text can be separate in each item
THANK YOU!
In case someone needs some visuals to trace my steps, I have attached the changes.
No worries. You don’t need to cast 3 times, just pull the pin 3 times, once for each variable.
And I’m a little confused about why you’re setting them there. Surely you already set them when you made the object. You can just read them during the line trace…
The Line Trace can also fail, when targeting non-phyiscsbodies. So I just wanted to make sure that the item was 100% grabbed, which, I figured, would definitely be the case after the Grab function was activated. If there’s a better place, I will move them immediately
Also thanks for the advice on cutting down the casts!