Invalid c++ variable in blueprint

Help!

Blueprint MainGameMode is derived from ALukeContinentGameMode,I want to instantiate questManager in MainGameMode,the log showed the constructor for ALukeContinentGameMode was run without any problen,but within the blueprint the QuestManager was invalid. Does anyone got any idea why is that? Any advice would be much appreciated! Thanks in advance!

The questManager is derived from UObject

ALukeContinentGameMode.h

ALukeContinentGameMode.cpp


OK, I finally figured it out with the help of a friend…
All I need is a simple delay node in blueprint!

You shouldn’t be new’ing that quest manager object in the constructor. Constructors in UObjects/AActors shouldn’t be doing a ton of work as they can get called by the Class Default Object and other things.

Instead do that work in Begin Play and it’ll be valid before you go into BP. The delay node “fixing things” is a hack at best. You could also look at making your Quest Manager into a World Subsystem and it’s lifecycle would be automatically handled for you.

Thanks a lot, this is exactly that kind of explaination and advice I need! I am a complete new starter that doesn’t know why it works and why it doesn’t work and doesn’t know where to go. Thanks for pointing it out for me!

Another dumb question: where should I place the heavy works in UObjects if not in constructor? I can’t find a Begin Play in UObject

For UObjects you can use PostLoad or PostInitProperties. I tend to go with PostLoad personally as that should be called after any serialization(loading an object from disk, etc) where PostInitProperties is a bit earlier.

PostLoad is a bit abused by editor tools, so I prefer PostInitProps.