I am building an RPG which includes a character class selection option. Once a class is selected I cast the actor to my game instance, then on begin play my controller gets the class from the game instance, spawns the actor, and possesses.
Taking control of the character works properly but I got bombarded by errors on my HUD. I added a delay of .01 and it works! However, other actors (such as my AI and loot drops) in the level which have references to my character are now encountering errors. Some I could resolve by adding delays to their begin play as well but not all.
Is there a better way to do this other than adding delays everywhere?
This makes sense, thank you! I updated my AI blueprint to what’s included in my attached screenshot. All of my classes are children of ThirdPersonCharacter. Seemed to work in a quick test where print string did cycle through Searching For Player before hitting Find Player.
Adding how I added the delayed begin play on the player character in case others run in to the same issue down the line. Thank you for your help!
Once you get into more interesting level structure like this, you will get timing problems. Delay is not the answer. For one, you’re right that is seems ■■■■. Two, the delay will depend on the host architecture.
A better approach is for anything that relies on your character to not assume it’s initially available. One way is, on begin play, check if you can see the pawn. If you can’t, delay for .1 and try again. Once the player appears, then call a ‘DelayedBeginPlay’ node.
Yes, it is still a delay node, but now we’re not guessing anymore…