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"

Spawn Actor with "Expose on Spawn" properties in C++

I'm trying to change the color of a projectile that I'm spawning in C++ code. I have a projectile color property on the projectile class and I'm applying this color to a dynamic material instance which I'm creating inside the constructor. Is it possible to set a value to this property at the time the projectile is spawned in C++?


 // Projectile color
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Projectile")
 FLinearColor* ProjectileColor;

This is on the character class:

 FActorSpawnParameters SpawnParams;
 SpawnParams.Owner = this;
 SpawnParams.Instigator = this;
 AMyProjectile* const Projectile = GetWorld()->SpawnActor<AMyProjectile>(MyProjectileClass, SpawnLocation, SpawnRotation, SpawnParams);

Perhaps there's a better way of doing this, but I'm not sure how to set the value of the projectile color property so that the MyProjectile constructor can apply it to the dynamic material instance.


Product Version: UE 4.8
more ▼

asked Aug 27 '15 at 02:23 PM in C++ Programming

avatar image

13 2 5 10

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

1 answer: sort voted first

Yes you need to use "DeferredSpawn" instead. That way you can initialize variables that you need to and then finish creating.

 AMyActor* pActor = GetWorld()->SpawnActorDeferred<AMyActor>(MyActorTemplate, GetActorLocation(), SpawnRotation);
         if (pActor )
                     pActor->//...setstuff here..then finish spawn..
             UGameplayStatics::FinishSpawningActor(pActor , FTransform(SpawnRotation, GetActorLocation()));

Hope that helps =)

more ▼

answered Aug 27 '15 at 02:35 PM

avatar image

2.3k 114 62 234

avatar image Bluarchon Aug 27 '15 at 05:26 PM

This is exactly what I need. Thanks Devero :)

(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