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"

C++ equivalent to "expose on spawn"

What is direct C++ equivalent to "expose on spawn" behavior found in blueprints?

In blueprints "expose on spawn" allows passing values into blueprint's construction script, (as I understand it) technically before object is added into scene.

In my project I have (C++) "init" method (which I call manually) for this kind of thing, but as far as I can tell, that one will be called AFTER object has been added into scene.

There is "OnConstruction" method that can be overrided, but its only parameter is FTransform, so I can't really pass values through it.

So, what would be an equivalent to "Expose on spawn" behavior found in blueprints.

Product Version: UE 4.10
more ▼

asked Dec 11 '15 at 05:33 PM in C++ Programming

avatar image

99 13 17 29

avatar image Slayemin Dec 11 '15 at 10:38 PM

This would be a UPROPERTY() META attribute, which looks like this:

UPROPERTY(BlueprintReadWrite, Category = "Default", Meta(ExposeOnSpawn=true)) bool ExposedVariable;

This would expose the C++ variable in the spawn node within blueprints, but if you need to know a variable value in C++ before you can finish spawning, you'll need to use deferred spawning.

avatar image NegInfinity Dec 11 '15 at 10:46 PM

That ain't it. I'd like to know how to pass parameters into object during construction in the manner similar to "expose on spawn". I'm not looking for a way to expose variables to a blueprint. After all, in unreal construcor only sets default values and isn't used to pass parameters into objects.

avatar image Modeus Games Sep 03 '17 at 07:45 PM

That worked for me, although mine looked more like this:

 UPROPERTY(BlueprintReadWrite, Category = "Default", meta = (ExposeOnSpawn="true"))
avatar image Constantin Suman Apr 26 '18 at 09:12 AM

Slayemin has a mistake (the "=" sign after "Meta"), it's supposed to be: Meta = (ExposeOnSpawn="true")

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

2 answers: sort voted first

Use SpawnActorDeferred to initialize the variables before spawning the object with FinishSpawningActor although there isn't any way to pass in the parameters within the spawn call as far as i can tell.

Edit : BeginDeferredActorSpawnFromClass is the way to go since SpawnActorDeferred has been deprecated.

more ▼

answered Dec 23 '15 at 01:03 PM

avatar image

70 1 6 8

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

In C++ you can call NewObject and set your variables or you can try this approach.

more ▼

answered Dec 11 '15 at 06:50 PM

avatar image

716 36 13 42

(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