Announcement

Collapse
No announcement yet.

set staticmesh from referenced blueprint variable in class constructor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    set staticmesh from referenced blueprint variable in class constructor

    Im currently removing hard coded paths from c++ code and try set them in blueprints.
    In my custom actor i have editable UStaticMesh or UParticle pointer variables, that can be referenced in the blueprint.
    Code:
    UStaticMesh *m_pStaticMesh = nullptr;
    For some reason this variables are always NULL, when i try to call
    Code:
    m_pVisualComponent->SetStaticMesh(m_pStaticMesh)
    f.e.
    It works when i set them in BeginPlay() function.

    #2
    Originally posted by Meldryt View Post
    Im currently removing hard coded paths from c++ code and try set them in blueprints.
    In my custom actor i have editable UStaticMesh or UParticle pointer variables, that can be referenced in the blueprint.
    Code:
    UStaticMesh *m_pStaticMesh = nullptr;
    For some reason this variables are always NULL, when i try to call
    Code:
    m_pVisualComponent->SetStaticMesh(m_pStaticMesh)
    f.e.
    It works when i set them in BeginPlay() function.
    Hi there!

    BP variables that you set in the Editor do not become valid until PostInitComponents!

    So you can't set them in the C++ class constructor.

    For this reason I typically use Begin Play, as I usually need to override that anyways.


    So the lesson:

    Never try to apply BP-set variables in the C++ constructor, they wont be valid yet

    Rama
    100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!

    UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

    Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama

    Comment


      #3
      [MENTION=552]Rama[/MENTION]

      Thank you, that make sense! :-)

      Comment

      Working...
      X