C++ Spawning a blueprint

Hi all,

I’ve switched to using unreal for my projects and have started learning the ins and outs.

I’m trying to create a small multiplayer game to try it out and learn however I’ve ran into a issue I can’t seem to resolve. I can’t seem to spawn an actor from within my OnWorldBeginPlay method in my C++ gamemode class.

I’ve looked around the answer hub with people offering suggestions and have tried all I’ve found to no avail.

My C++

I’ve tried to recreate this in a blue print and it works correctly. But my C++ code just wont, there’s no errors in the output nothing.

Can anyone help?


I feel like an idiot. If anyone sees this it is because for some reason you can’t spawn the actor in the OnWorldBeginPlay delegate. it actually has to be BeginPlay. Sorry for being a moron.

Hello! Is Phaser UClass successfully found by FObjectFinder? Also, is AAPickup correct base class for Phaser?

The blueprint asset is UBlueprint while you got UClass in template argument, so you should use UBlueprint instead.

If spawn fails it always output error with reason in output log so check it out (you can find output log in Window->Development Tools->Output Log). If issue above is the things then it should tell you you got nullptr on class.

Potentially StartPlay may also be executed after OnWorldBeginPlay making your function not bind in time. In this case oyu should not get a log. You can double check by putting breakpoint on OnWorldBeginPlay (click space in VS between line number and code text area to place it) and run debugger.

If you plan to use GameMode blueprint anyway with conjunction with C++ i would not reference blueprints in C++ all together and use TSubclassOf UPROPERTYs instead, they a lot safer and should work 100%.