I have three classes: PortalGun, PortalManager and Portal. PortalGun is using PortalManager to spawn Portals, but Unreal crashes after trying to spawn a Portal.
Portal = GetWorld()->SpawnActor… this line is responsible for crashing the Unreal Engine. There might an issue in the way how the PortalManager is declared and/or initialized in the PortalGun/PortalGun().
you can post code directly to the forum (so you don’t need to make images)
"`"x3 the button typically next to 1 then on another line do it again
anything in between will be considered code.
on the problem at hand, I am going to presume that these portals will be spawned onto things that have collision like walls, and then the portal itself will also have collision when it spawns.
if this is the case then what is probably happening is the Physics system is throwing up its hands and giving up in a crash.
maybe because your APortal SceneComponent collider doesn’t have GenerateOverlapEvents == true
you might be able to fix this by feeding in the next argument of UWorld::SpawnActor<T>(T::UObject, FVector, FRotator, FActorSpawnParameters)
besides looking at the collision response of the APortal objects collider
additionally instead of feed in the UWorld* because any actor has access to GetWorld() (which you are doing anyways in this function) so you don’t need to pass it, maybe pass the FRotator of what would probably be the Normal Vector of the hit, and you could even pass a FHitResult& which would include the location of impact and the Normal Vector of the impact which you could then use to get the rotation.
your
const FRotator Rotation(0.0f, 0.0f, 0.0f);
// ^this is the same as
FRotator::ZeroRotator // which is a static member variable of the FRotator class
@gardian206 Thank you for your response. I will break my message into points.
Code instead of images → will use that
I have checked the collision of the Portal and it has none (imagine from UE5 BP_Portal)
I also added the SpawnParams to the spawning actor method as you suggested.
That UWorld* is a thing from the past, I was testing between PortalManager inheriting from Actor and not. I removed it, and I added a reference to the HitResult, since it will be usefull to create Portal and the correct location with rotation, but I will focus on that one after I deal with the crash.
ZeroRotator - good one, I used it instead my previous const Rotation.
After all UE5 is still crashing, actually there 2 reasons. When I fully regenerate the project (remove binaries and intermediate folder → use “Build.bat PortalDemo Win64 Development” in cmd → generate visual studio project files → build the project from VS) then I am able to boot the project and “play” the game. After I press left button (which activates the CreatePortalEnter() ) the UE5 crashes with the same crash report as above. After I try to boot the project again, UE5 crashes with another report:
"Crash Report - due to the "PortalManager = NewObject<APortalManager>();" line
Okey @Hexavx, that helped. No more crashes so far, but Output Log shows one more warning and Portal is not spawned, after spawning APortal:
LogSpawn: Warning: SpawnActor failed because no class was specified
@ZaharKostic ou, you are right, I spawn PortalManager instead of BP_PortalManager. Do I need to add a class to PortalGun (class that has PortalManager pointer) and set it in UE5 to BP_PortalManager or there is some other way?