I ran into an issue where OnComponentBeginOverlap fires before BeginPlay starts on a spawned pickup actor.
I have a character with a collision sphere that detects pickups and automatically collects them on overlap. This works fine for normal pickups that spawn in the world.
However, in one case I need to spawn a pickup inside the character’s collision sphere, but I don’t want it to be picked up immediately. I want it to only be collectible after it exits the collision sphere and reenters it.
My problem is: I have a boolean variable in the pickup to see if I can pick it up (default = false). In BeginPlay of the pickup, I set this boolean to false again (just to be sure). But when the pickup spawns inside the sphere, the character’s overlap event fires first, before BeginPlay of the pickup has executed. When the character checks that boolean on the pickup, somehow it reads as true, even though the default is false and I’m setting it to false in BeginPlay. So the pickup gets collected instantly.
I also have an End Overlap event, that sets thd boolsan to true, so that I can collect it later.
This behavior (collision check before begin play) is made intentionally because often the spawn location has to be modified to avoid spawning an object inside another object.
Your fix should be simple though. Add a CanBePicked boolean variable - set its default to false and on BeginPlay set it to true.
Now all you have to do is when you overlap to check this variable. Everything that was spawned inside the collider will initially have it as false. But once begin play has passed, every other BeginOverlap will have it as true.
I assume that the overlap is checked in the character:
To be honest, this is exactly what I did, although in a more roundabout way. The character still read the boolean as True. I assume it was because the last time it checked, it was True, but I have no idea why it did not see the default.
However, now that I checked the program again, for some reason the BeginPlay goes before the OnComponentBeginOverlap. I have no idea why, or what changed during the night, but thanks to this, now the program works perfectly.
its because BeginPlay order inst guaranteed and can/will change between editor/packaged builds so dont assume its fixed. if you need a fixed pattern its better to use another method such as a spawn manager