You can’t do that and it because UE4 create object little differently, instead of initiating new object, it stamps default copy of class object (DefaultObject/CBO) in to the memory creating new object, so contractor is avoided. Create a function with parameter in ABot and call it right away after spawn or just set variable after spawn.
Hello everyone,
I am wondering how to pass parameters when we call the function SpawnActor.
I am actually spawning an actor like that:
ABot* const SpawnedEnemy = World->SpawnActor(WhatEnemyToSpawn, SpawnLocation, SpawnRotation, SpawnParams);
but I have a ABot constructor that can take a parameter (a float). The SpawnActor only calls the empty constructor.
What can I do to call ABot(float Time) when I spawn my actor?
Thanks!
Ya that’s what I did, I just thought there would be a better way. Thanks for the quick answer!
If the main concern is execution of BeginPlay, etc before you’ve had a chance to set variables, then you can try calling SpawnActorDeferred instead of SpawnActor. This gives you a chance to setup your variables after which you can call the FinishSpawning(…) function which then calls BeginPlay, etc