== object not working?

Hi, I have a weird problem that hasn’t happened to me before with nearly identical code.

Using the above code, if the actor overlaps with a first person projectile, it doesn’t detect it as one.

This code, however, works for the first bullet (because its just getting the first actor of that type) and doesn’t detect any of the bullets after that.

I don’t mind the second code not working; I understand why that’s wrong. However, I feel like the first picture I sent should work perfectly fine… any help?


1 Like

First code doesn’t work because there is no cast. If you cast it to first person BP then compare, it should work.

On that note. Implement an interface and check for the interface existence…

1 Like

It has nothing to do with casting. Comparing object references is done by comparing the memory address nothing more. The object you are are comparing with in the first example is simply not the object you think it is and therefore it fails.
The first example is probably comparing the overlapping Actor with the CDO (class default object).

By your own definition it has everything to do with casting.
What’s the “reference” to the option you select in the == statement ?
Nothing. it’s not a live actor. so what would you be comparing to?

Whereas, if you cast that class then compare, the engine (assuming the cast is a success) will be able to determine that it’s a match.

Casting and Comparing is two very different things. You cast if you want to “treat as” and you compare for equality if you want to know if it is the same exact object.

By definition, that is Precisely what OP is trying to do:

If he had an active reference and needed to see if they matched, then he could use some different system.

An acceptable one would be to store that initial reference, then test if the reference is the same value on End Overlap.
You can do that without having to cast.

But that’s got nothing to do with what the OP asked now does it?

It doesn’t work because “other actor” is a non-casted reference, and would have to be compared for equality against some other reference.
To be able to use == like shown, you need to cast prior.

Get Class Equivalency makes more sense than Casting in this example. Casting I would only do if I actually had to perform an action on the Projectile but I see where you’re coming from.

Shouldn’t it ‘loop’ back around to itself (running again every time it is ‘used’) at the branch so it is always ready to ‘go’ again? ?

Perhaps making it happen On Overlap END instead will help? I have seen that problem in a few different cases (like the old on Button Down or Button Up problem :slight_smile:

Is it supposed to ‘fire’ every time there is actor over lap, or fire when there is a ‘Trigger pulled’?
I usually see things ‘fire’, as an Action that is linked to a hardware Trigger in project settings/ Input, (or is your overlap necessary and related to animation?)

Also, perhaps it is tangentially related to this:

Good luck!

That it does. Soft reference solve would probably also work.
Still, we don’t know what the user intends to do with the actor - 9 times out of 10, when I do this I need access to a specific variable to toggle - So checking a Blueprint Interface makes more sense and avoids casting altogether.
Actor implements interface? Call the interface function. Done.
Simple and neat.

I didn’t think this would work, primarily because I already tried casting (although in a slightly different way) and it didn’t work.

However, this tangled ugly code works. Thanks guys!