Hey all,
I want to spawn an Actor with some default values set before the constructor is run.
Basically I want to change the scale of certain components based on a value set before the object is spawned and have them built in the constructor with my custom values.
In Unity/C# I would create the object and set values before spawning it into the scene, something like:
var a = new Object();
a.size = 150.0f;
Instantiate(a, location, rotation);
Can anyone educate me on the best way to do this? I think I need something like custom spawn parameters but I’m having trouble figuring this out.
It seems quite simple to do in blueprints as I’ve seen here:
Any help would be greatly appreciated. Hopefully this isn’t a stupid question but I’m sure there’s an obvious answer that my brain cant figure out right now. C++ in UE4 is still quite new to me and translating what I can do in blueprints to C++ can be tricky.
Override PostInitializeComponents() and set your transforms there. This is post-constructor of course.
If this is not what you are after you can use GetWorld()->SpawnActor, you can specify spawn parameters here and an optional template AActor as well as other useful things
Thanks for the replies. Calling a function on my new actor and passing it my values is working fine.
I’ve been trying to figure out how I can create a custom set of spawn parameters as that seems like the logical way to initialize an actor with set values rather than changing them after the fact. However your solution work fine for my purposes.
Thanks!