I’m still getting to grips with UE4 and blueprint as a whole so I keep running into problems tinkering with an idea I’m playing around with. I’ve looked online but barely seen anything on how to use bools which I think is what I need for what I’m trying to do so I’ll explain as best as I can what I’m trying to do and see if anyone can figure this out :3
I’m trying to create something that acts as a power source. So that when a player goes to this source, they can absorb energy from it which will be active. These sources would be dotted about various levels in the project I’m working on, hence making it as a class. I have created a class blueprint called Source, I’ve added a temporary default mesh and trigger volume around it in the components tab. I also added a hovering piece of text which has its visibility toggled when the player is in the trigger which works. So far so good. The part I am struggling with is interacting with it. I have it so that when you walk up to the object, the trigger volume enables input by the player controller, this seems to work.
I have created a bool called power. This is how I think I should be doing this? So that any time the player uses a power source, the state of having ‘power’ will be true. As a separate thing in the class BP, I have “E Pressed” connected to a branch which checks if power is true. If false, it ticks the bool ‘power’. If it is already true, i.e. the source has already been interacted with, a string pops up saying ‘Already enabled’. When I drop the class blueprint ‘source’ into the world and test it out, it all seems to work. But when I add the class blueprint again, so a duplicate is in the world, things don’t quite work. If I go up to the first one and interact, I get ‘Power enabled’. If I go to the second one and interact, where it should say ‘Already enabled’ it instead classes ‘power’ as false and enables the power again.
As I said I’m still pretty beginner so I could be almost there, I could be going about this all wrong I’m not sure. I assume the bool in every subsequent version of the class blueprint is named differently with _2 at the end or something which is why it is not working. Does the bool ‘power’ need to be in the open level BP graph instead? Should I use something instead of bools?
Each blueprint instance in your world will have it’s own copy of your power bool. If you want this to only happen one time, put that piece in your player or some other similar place.
[=;175843]
Each blueprint instance in your world will have it’s own copy of your power bool. If you want this to only happen one time, put that piece in your player or some other similar place.
[/]
Thanks for replying.
So I would need to make the power bool something that is a part of character/controller class?
How would I go about referencing this in my source blueprint class? So that when I walk into the trigger volume on source and press E, it references the power bool in the main character class and turns it to true?
add small script in construction level blueprint (because only level BP knows all actors in it), and for each actor check if its same class as your source
Store pointers (references to those power source actors) inside array in level bp or game state (game state works better for this).
Add 2 variables in game state: one that says event of player and power source happened, second id of power source (ie. index from array you made in construction script). On player overlap with power source set that global (inside game state) event happened to true. And global ID power source to index of that from event.
When event happens set that event happened bool back to false, read id of power sourcce, gets its reference pointer out of array and cast to it.
[=Nawrot;175864]
add small script in construction level blueprint (because only level BP knows all actors in it), and for each actor check if its same class as your source
Store pointers (references to those power source actors) inside array in level bp or game state (game state works better for this).
Add 2 variables in game state: one that says event of player and power source happened, second id of power source (ie. index from array you made in construction script). On player overlap with power source set that global (inside game state) event happened to true. And global ID power source to index of that from event.
When event happens set that event happened bool back to false, read id of power sourcce, gets its reference pointer out of array and cast to it.
[/]
Sorry to be a pain but I’m still really beginner with blueprint so I’m not sure about half of what you posted.
I used a cast previously in a tutorial, I understood that it made reference to something in a different blueprint but I’m not sure how exactly it works or how to apply it to my situation. I sort of understand the process you described logic wise, I just don’t understand how to do that in practice. If you wouldn’t mind, could you elaborate on your explanation? I’m struggling to find info on the web on casts and such.
Casting can be a bit difficult to understand. I posted here a while back with an explanation of how casting works that seems to help, take a look:
[/]
Thanks for the reply, I’ve had a read and still don’t quite get it but I am pretty beginner so it’s all a little confusing at first hehe.
The current thing I’m trying to do is have the power bool in the level blueprint so it is a global thing. My only problem now is, I don’t get how I can use the trigger volume from my ‘source’ class blueprint to activate it. I tried simply copying the event node from the source BP but that didn’t work. Is there a simple way to do this that I am missing?