Download

Script behaves incorrectly when made into a function (+ another Q)

I finally got around to buying UE4 about a week ago and have been attempting to learn how to program through blueprint (I have no experience with code and would be hopeless with C++). I’ve been fiddling on and off with figuring out how to open and close a door (seemed like a good place to start). I’ve nearly completed most of the functionality I want (well, for now at least. I’ll explain further down) but I’ve ran into an interesting problem.

The method for opening the door I chose to go with is a line trace that allows the player to open the door upon pressing F so long as they are in range and looking at the door. The code I had worked just fine, however, I wanted to cleanup the graph and so I consolidated things within functions to save space. Everything worked fine except for the Check Usable Object function (the line trace). As far as I can tell there is no reason for the error I am getting, but I’m sure there is something I don’t know about that is going on. Anyway, to make things easier than my—usually incoherent—ramblings, I’ve screencapped the script (is it script or code or graph or something else?) in question.

YCrw68R.png

Everything looks fine and dandy, but, as I said above, the Check Usable Object function is giving me problems. Here is a picture of the function.

eaHrMmF.png
(Note: I had actually added a Switch Has Authority node before the line trace, I just took the screencap before then)

The problem I am having is: once the line trace hits the door, no matter where I go, the door can be triggered to open and close despite the line trace no longer hitting the door. To make sure I didn’t just somehow script things wrong (even though I copied the original script directly into the function when I was consolidating things) I tried the same script but exposed in the event graph rather than in custom function.

cLl8OEO.png

This fixed the problem and I have no idea why. By chance do any of you guys know what amateur error I made?


Also, I had a couple questions beyond that I would like to ask. First, I would appreciate if you guys could give a look over of the rest of my script and tell me if I have any redundancies I could get rid of or if I’ve made anything that won’t function the way I’m expecting (with both the Use script above and the door script below).

85Xbaff.png
rAkC1i4.png
ZXHHkIp.png

Beyond that I was wondering how I would go about adding an icon to the HUD to show the door can be opened/closed similar to that of ArmA 3. By that I mean an actual HUD element rather than a widget that pops on in in front of the door. I have no HUD script set up at the moment, though (probably worth mentioning as I figured it may affect possible answers to my question).

Eventually I will have other questions as well (as the door model I was testing this on will one day be part of a player created wall in part of a player built base), but I think I’ve asked enough for now. Any and all help is appreciated. :slight_smile:

Hello,
About first part, mistake is that even if your function goes false, when it is done then the function after is executed. To do it fine you would add your “does implement interface” bool as output value and check it out of the function to a branch to do or not the next function.

About second part, i’ll read it later but i invite you to not post lots of questions in same posts as replies will be quicly messy and maybe ignored. And to wait a bit to not post a dozen of posts to not make people not replying to you. In your interest.

Is it really just that? Not gonna lie, that just confuses me more lol. So, despite that I have a branch to check if the Does Implement Interface bool is true within the function, the function will still execute once the bool has been triggered as true once? If I were to remove that branch within the function and make it external to it that should fix my issue then?

Don’t worry I intend to be conscious of how much I’m asking as I certainly don’t want to spam everyone. :slight_smile: Thanks for the answer, though!

The thing is that what is in the function stay in, except if you create an output. So when your function is solved, if your bool has no output, your next function can’t know it and as there is nothing related to it, when first function is done, in a way or another, then the next one is fired. Even if the false is not connected to end of function, when it is reached, function is done. Then as the next one is directly connected, next one is fired. Best way is to use output ability of function.

About second part, you may be could do all in same bp by setting values not in function but most of changes would be more like personal style more than better or not, imho only.

About your hud, you would have a look to umg 3d widget : https://docs.unrealengine.com/latest/INT/Engine/UMG/HowTo/Create3DWidgets/index.html
and the inventory tutorial which shows names elements in level, you’ll find a lot of ideas there : https://docs.unrealengine.com/latest/INT/Videos/Player/index.html?series=PLZlv_N0_O1gZo6zXTHGGSH8gxaA7a_zCt

Alright, I think I get it now, thanks. :slight_smile:

The Use/Interact w/ Object script is all the MyCharacter BP and the Open/Close door script is all within the Door BP. Everything that is in a custom function was put there just to tidy up the “main” area in the even graph. Indeed most of it will be personal style.

Thanks, I’ll give those a look after I get some sleep. :slight_smile:

Sorry, just one last quick question. I’m still not completely sure as to how RepNotify works so I’d just like to make sure the way I have it set up for the door is correct. What I think it should be doing (and what it seems to be doing) is, upon the player entering the area where the RepNotify becomes active the player will be made aware of the door status (because it is the variable that is replicated) and also the correct door rotation (because the OnRep Door Status function calls to set the door’s rotation using the NewDoorRot variable). Would it be correct to say that is what is happening?

Also, sorry if that sounded like gibberish, I tried my best. :frowning:

I haven’t use replication enough so the best i can do is to link you : https://docs.unrealengine.com/latest/INT/Resources/ContentExamples/Networking/1_4/index.html
https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/Networking/ReplicateVariable/Blueprints/index.html