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!
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!
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.