Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Setting actor properties pre-spawn

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: https://www.youtube.com/watch?v=Qv6pTOVcVDA

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.

Product Version: Not Selected
more ▼

asked Sep 14 '14 at 10:21 PM in C++ Programming

avatar image

56 8 15 15

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Sep 14 '14 at 11:55 PM

avatar image

131 6 5 18

avatar image staticvoidlol Sep 15 '14 at 06:31 AM

Braeden's approach is correct. I have also encountered this issue, and I've written up some more details in this forum post if you're interested.

avatar image Hum Sep 15 '14 at 09:44 PM

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!

avatar image EstherZuidgeest Mar 31 '15 at 03:47 PM

I'd like to add parameters while using the spawn actor.

APiece* NewPiece = GetWorld()->SpawnActor(PieceSpawnLocation, FRotator(0, 0, 0));

But i have no idea where in this line I could add my parameters.

doing it like this doesn't work

APiece* NewPiece = GetWorld()->SpawnActor(PieceSpawnLocation, FRotator(0, 0, 0));

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question