x

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"

Adding new components based on property change in Editor(Not @ Runtime)

Hello everyone!

Details :

I have been creating a class (Derived from APawn) in C++ that I would like to expose to Blueprints (So Artist/Designers can more easily modify and create assets). Creating a derived Blueprint from the C++ class is easy enough, however I would like some variables and arrays to be populated by changes made when editing the blueprint, also it would be preferable to have new objects and components dynamically added based on said changes.

I've looked into:

  • The Constructor -- (Useful for adding new components, but no properties are reliably initialized to create said components)

  • PostEditChangeProperty -- (Was added to both the Actor class & a custom USkeletalMeshComponent class, never successful in getting it to execute.)

  • PostInitializeComponents -- (executes at run-time and not in editor)

Appropriate reference links:

An example:

  • I have multiple skeletal meshes flush with sockets and bones, which will be used to spawn weapons, cameras, sound sources, effects, thrusters, etc.. (essentially a base mesh & rig for a modular vehicle).

  • The goal is to retrieve an array of all bone names for the skeletal mesh and save that to a TArray of FNames while in the editor (NOT @ runtime).

  • When a USkeletalMeshComponent were to have it's SkeletalMesh field set, I would need a way to access that new Mesh reference and call GetBoneNames().

  • Then it would be preferable to be able to create new components for certain bones/sockets.

I've gotten partially there (I think), I came across this : Setting Internal actor properties in editor. Which lead me to the following:

  • PostLoad()

  • PostRegisterAllComponents()

These only seem to work when the actor is placed in the level, in addition it only seems to fire once. I created a quick workaround BlueprintCallable UFUNCTION in the C++ class that manually calls RegisterAllComponents(), and attached that to the constructor graph in the Blueprint class editor. This seems to update the arrays correctly for the actor placed in the level.

Detailed Below:

Header relevant code: //Header

     virtual void PostLoad() override;
     virtual void PostRegisterAllComponents() override;
 #if WITH_EDITOR

     //Called by blueprint constructor to refresh the components.
     UFUNCTION(BlueprintCallable, Category = SFIEditorFunctions)
         void RefreshComponents();
 
 #endif
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;

CPP relevant code:

 #if WITH_EDITOR
 void ASFIShipCore::RefreshComponents()
 {
     RegisterAllComponents();
 }
 
 void ASFIShipCore::PostRegisterAllComponents()
 {
     if (ShipBaseMesh->SkeletalMesh)
         ShipBaseMeshSockets = ShipBaseMesh->GetAllSocketNames();
     if (ShipCockpitMesh->SkeletalMesh)
         ShipCockpitMeshSockets = ShipCockpitMesh->GetAllSocketNames();
     Super::PostRegisterAllComponents();
 }
 #endif
  

Class blueprint ComponentRefresh-Blueprint

I apologize for the very long-winded explanation, and if more information is needed I will happily provide it. To summarize what i'm asking:

  1. Is it possible to have Uproperties update in the Blueprint Class Editor realtime?

  2. If so, can those properties be used to create and attach new components in the Blueprint Class Editor?

!Note : I have tried using NewObject() & AddComponent() in both the PostRegistertAllComponents() & OnConstruction(), to no avail.

I appreciate the time anyone has taken to read the above!

Product Version: UE 4.9
Tags:
more ▼

asked Oct 02 '15 at 05:35 PM in C++ Programming

avatar image

invertedJoy
333 3 6 12

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

1 answer: sort voted first

Hi,

Have you tried https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/OnConstruction/index.html

It's the C++ closest equivalent of the Construction Script for Blueprints. It get's called every time a change happens.

For dragging an object in the world using the transform gizmo, PostEditMoved get's called and OnConstruction get's called only for blueprints that have bRunConstructionScriptOnDrag set to true, but you can overwrite it.

more ▼

answered Feb 12 '16 at 12:54 PM

avatar image

Plosnita
277 5 8 22

(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