So I’m not 100% sure this is a bug in ue4 or just something i have set up wrong in the blueprint scripting. I have this boolean called “Apple near?” which is stored in the Third Person Character with the default value set to false. I have a branch hooked up to an event tick inside a different actor that will see if the third person character is colliding with this. If it does than it will set Apple near to true. However, i don’t think this is working correctly when I use the “is overlapping component” node because even when I set Apple near to true on here above is a branch which tests if apple near is true and it’s saying it’s false:
252590-
If someone could tell me what i did wrong here that would be great, or if i haven’t scripted anything incorrectly and that this is most likely a bug. Thanks!
How are you checking (printing?) whether the variable is True - it’s not in this screenshot.
I’m sure what you mean by printing, but just above where I set “Apple Near?” to true is a branch where Apple near is the condition, and the graph flow is feeding into the false instead of the true when it’s clear the variable should be true.
Why don’t you just set On Component Begin Overlap event to know when you collide with the apple and set the variable to True? Checking if there’s an overlap every tick seems counter-productive.
Maybe there’s something after your tick that sets the Bool to false every time.
I strongly recommend removing the tick from the execution sequence and achieving your goal otherwise.
There is a much easier way of going about this. Also, I would recommend against using “ticks” to drive logic. If it is something that has to be performed on a tick, can it be used on a timer that can be enabled/disabled…?
Anyway… What I would do instead of using the “Is overlapping” check and instead set the value to true when the character overlaps the “Apple’s” collision sphere using the events for the collision sphere:
OnBeginOverlap - Set the value to true and OnEndOverlap - Set the value to false
Hope this helps! Also did a quick video tut for you!
I want to target a specific component from the third person character which is why i am not using on component begin overlap. And there isn’t something after the tick that is setting the boolean false since I have tested this out with a test variable i created and I still received the same results.
Can you provide more of your blueprint? Nothing’s really clear from the abstract we have.
Thanks a lot for putting the time into making this, but is there a way I could reference a specific component from an onBeginOverlap? Since there is a specific component in the third person character I don’t want to activate this check. I would only like the mesh of the Third person character to activate this.
Well, I can’t tell you what the problem is with the Bool, but I can tell that what I see in the screenshot is, to put it mildly, not good. In general, using even one Cast node with Event Tick is a bad idea, and you have 5 of them in the last two positions of your sequence, and what you have in the previous ones I’m too scared to imagine.
I’m begging you to try and review your logic before it’s too late and everything in your game is based in it. You can make lots of stuff happen with events. Answering your question below - yes, you can reference a specific component for the On Begin Overlap event, just select it in the list of components and you can add any event you need from the Details list.
I am curious as to why multiple cast nodes are a bad idea and what is a better solution, since saying “it’s a bad idea” and “review your logic” is kind of vague lol. In terms of referencing a specific component for the On Begin Overlap I can’t create overlap events inside of an actor that the component doesn’t belong in. Since “capsule” is in the third person character.
Just a quick example: create a For Loop, set the last index to, say, 500, and connect the index output pin to a Print String node. Then launch your game and activate the For Loop once. You’ll get numbers on your screen from 0 to 500. Everything’s fine, seemingly. Now hook the same For Loop to Event Tick. I don’t know what CPU you’re using, but I’ve got an i7-8700, and it starts lagging as hell. And these are just simple operations. Casting to another blueprint is generally more expensive in terms of processor time, and you’re doing it multiple times a tick.
About vagueness, what’s vague in “Use events instead of casting”? And you don’t need to access your Character’s capsule from your Apple BP. Overlapping works both ways. You can create an overlap event for you Apple in the Apple BP. And when such an event occurs, you can Cast to your Character BP ONCE and do what you need to with it.
Hard to disagree with Tuerer.
why multiple cast nodes are a bad idea
Cast nodes are not a bad idea, they’re a brilliant idea and quite often they are strictly necessary. Using them incorrectly is a bad idea, though! They are slow to execute. In this very case, you could do a single cast at Begin Play, store the reference to the Player Character and use that. Here you are performing 300 completely unnecessary casts every second… (at 60fps) just to gain access to the player character. And that’s not counting the rest of the sequence spaghetti.
You may not feel it yet but it will all pile up. Even though this may not be a product you’re releasing and you’re just messing about with the editor, it solidifies bad coding practices. It makes the script hard to read and it will make it hard as hell to debug when things go wrong (like in this very case, for example).
Generally speaking, the logic should be driven by events and responses. Some things must be strictly in Tick, of course! Setting boolean values like that is not one of them.
btw,
review your logic
is an elegant (if nonconstructive) way of suggesting that your stuff is not that great. They were just being nice ;p
Yep. So the collision sphere that you have set for the character’s mesh to overlap with would just need to have a custom collision response to a set object.
Go to Edit->Project Settings->Engine->Collision
Here you can add a “New Object Channel” - set its name to something like CharMesh and set its default collision response to “ignore”
Now on your collision sphere on your “Apple” you would set the collision to to ignore everything else but the new “CharMesh Object Channel”
Not sure if that is 100% correct or not but you should do a search for UE4 Custom Collision Channel or something along those lines. Hope this helps!
I understand what you mean by casting is very expensive when being used every tick. I have the same CPU as you and I’m also getting the low fps lagging when connecting this with an event tick. And when I say vague I mean you didn’t provide any other alternatives to casting to the third person character. Considering I am not experienced in UE4 blueprint scripting, I am not sure how I would use these events for an alternative to casting. How would I achieve a variable from the third person character inside the blueprints from another actor?
I have actually done a framerate test with and without the actors that contain these multiple castings and the difference was about 40 fps. 119.00-120.00fps without the casting and 75-86fps with the casting. Thank you for opening my eyes to this since one day i would like to release this game. Do you know of any alternatives or a way i could fix this? Thanks.
As I can see in your screenshot, you are setting several variables in the Character blueprint and none in the Apple blueprint. You can set them like this, but you can set them inside the Character blueprint as well. For example, you can add a tag to your Apple, and when the Character collision capsule (or any other component to your liking) overlaps something, you check if it’s an Apple or not, and then do your stuff.
Next, when you overlap the Apple, you probably want something to happen to it. If you want to pick it up and destroy it, or put it into your inventory, you can do it directly without casting. If you need to get some data from within the Apple blueprint, then you Cast to the Apple blueprint, of course.
If you need to perform a function in your Apple BP and don’t need to receive any data from it, you can do it from within the Apple BP:
So the Character and the Apple will perform their own functions.