In an ActorBP construction script, I couldn’t use GetPlayerPawn method.
So I implemented a function in BlueprintFunctionLibrary and use it in the construction script.
It worked.
Is this good way? Or, are there other way to get player pawn info on construction script?
There are reasons why certain things are not available in the Construction Script. Do note the order of execution and what hooks up to whom is different in the editor and in the standalone.
Before relying on any workaround too much, do consider testing it. Hard to tell whether this will work OK since we do not know where you’re using it.
If it’s an actor dropped in an unloaded level, it might work. I wonder if anyone can tell for sure if this is safe.
Rule of thumb - assume nothing. Generally speaking, it would be safer to do it on Begin Play however tempting Construction Script may seem. There are some horrible gotchyas to be had there.
The very fact that you do see the World Context Object pin tells you that something unorthodox is happening here.
Thank you.
But actually, I want to set InitialSpeed in ProjectileMovement on spawn.
If I set initial velocity in BeginPlay, it doesn’t work…
Resolved from this question.
- Create new float variable in Projectile Blueprint to spawn.
- Activate Expose on Spawn
- In construction script, set the variable to ProjectileMovementComponent::Initialspeed
- When we ‘spawn actor’ pass a float value to float input pin we’ve made in projectile blueprint.