Home Unreal Engine

Add Dynamic SM Components?

GhosTDoG
polycounter lvl 6
Offline / Send Message
GhosTDoG polycounter lvl 6
Hi,

Is there a way to "Add Static Mesh Components" dynamically?
As you can see in the BP, I Have to add a complete new "Add Component" Block for every "New Mesh" + "New Material" I want to add.

Is there a way to use the Array dynamically with a flexible amount of mesh components?



Thx

Replies

  • Obscura
    Offline / Send Message
    Obscura grand marshal polycounter
    Check out the "for each loop" node...
  • GhosTDoG
    Offline / Send Message
    GhosTDoG polycounter lvl 6
    Thx Obscura.

    The next big issue-> I want to a attach the meshes to a socket in a static mesh (first mesh) - how can I get the info of that from the array:

    Maybe I can a add a SM Component as a root mesh with the socket - so the root would be static and  the further meshes would be dynamic?
    I'm also struggling with the Materials.
  • GhosTDoG
    Offline / Send Message
    GhosTDoG polycounter lvl 6
    Worked, but I don't know, if that's the smartest way? :D


  • GhosTDoG
    Offline / Send Message
    GhosTDoG polycounter lvl 6
    Any idea how I can set up the materials to the corresponding mesh array?

    f.e = "Array 0" has "Mesh A" assigned and now I want to get the Materials of "Mesh A". Tried it with Get Material, but I only Get the last Array Mesh.
  • Obscura
    Offline / Send Message
    Obscura grand marshal polycounter
    I''ll rather make an example image later today. But based on what you are saying it sounds like you are doing what you are doing outside of the loop, right after it completed. This is why it returns only the last element. You should do it inside the loop. Then the array element output of the for each loop will always return the current mesh.
  • GhosTDoG
    Offline / Send Message
    GhosTDoG polycounter lvl 6

    Thank you Obscura. :)

    Maybe I should explain, what I actually wanted to achieve:

    Essentially just a simple "Dynamic Prefab", which attaches arbitrary SMeshes to a socket in the main/root SMesh -> f.e House with door; house with door + window; airplane with door + window....

    Regarding the Materials - it would be enough to get the assigned materials/ indices from the Static Meshes, which later on show up in the actor (as editable variable), so I can drag n drop new materials in the slots to the SMeshes in the actor or whatever will work (I tried it with get material, but as I said, only got the last array mesh or nothing worked at all - no link to the SMs in the mesh array).





  • Obscura
    Offline / Send Message
    Obscura grand marshal polycounter
    Alright, having the material list to show up is complicated because dynamically added meshes won't show up in the actors hierarchy. What you could do is to make a struct, and populate it with the necessary parameters you want to change, and to include an array that is a type of material interface. Then you would need to have a pre-pass in the construction script, where you check all the spawned meshes, and collect material indices and put them in the arrays. This is necessary in order to have the same amount of indices exposed as how much materials the mesh has. Then you could change any of them. The setup would be still funky and I'm pretty sure you can't set this up if you can't really deal with a for each loop (not an insult!). I would rather recommend checking out some tutorials or articles about this, maybe even existing marketplace assets.

    https://www.google.rs/search?client=opera&q=unreal+engine+prefab&sourceid=opera&ie=UTF-8&oe=UTF-8

    With UE4.22, you can have editor widgets. This would make things somewhat easier, and make the aforementioned setup would look and work less hacky. 
  • GhosTDoG
    Offline / Send Message
    GhosTDoG polycounter lvl 6

    Thx a lot for your explanation...will check your link. :)

    But I think the time investment will not pay off in this case till I reach that scripting level.

    I only tried it this way, because I always get " Static Mesh Actor has NULL StaticMesh property" warnings with a "Set Static Mesh" Array, so I tried it with "Add Static Mesh Component"

    But warnings are no errors, so I can live with this issue and it worked so far.





Sign In or Register to comment.