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"

Static mesh subcomponent in code, spawns at world center when placed.

Hi!

I wanted to create a pickup item for my game similar to the "PizzaPickup" described in the programming introduction video, but having the UStaticMeshComponent already defined in my C++ class. So in the header file I defined the following property:

 UPROPERTY(EditDefaultsOnly, VisibleDefaultsOnly, Category = Pickup)
 TSubobjectPtr<UStaticMeshComponent> PickupMeshComponent;

And in the implementation constructor I did:

 PickupMeshComponent = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh"));

I did it this way because I wanted to have a blueprint with the mesh component already available, but with no mesh set. Also, i wanted to set a default offset of the mesh, slightly off the ground. Either way, with or without the offset, I launch the editor and create a blueprint based on my class. Setting a mesh in the component, and everything looks fine in the blueprint editor.

But once I place an instance of the blueprint in my scene, the bounding sphere gets placed correctly, but the mesh itself seems to spawn in the world center. No matter how many instances I place, the root (sphere) always ends up in the correct location, but the meshes are all bundled up in the same spot.

For now I've added the static mesh component via blueprint, and then it works fine. But I'd really like to have this in the code, so I can set some default behaviour for pickups, such as the mesh offset off the ground, and some pitch.

Any ideas? Am I doing something wrong?

Product Version: Not Selected
Tags:
more ▼

asked Mar 26 '14 at 02:12 PM in C++ Programming

avatar image

Gebba
21 2 3 6

avatar image Gebba Mar 26 '14 at 02:31 PM

And I should probably mention that moving the instance does NOT move its static mesh component, only the root component. I've tried setting the meshes relative location and all sorts of things in the code, but I keep getting the same issue.

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

2 answers: sort voted first

Even though the components are created inside an actor object, you still need to attach them to have them inherit transforms. Try adding this:

 PickupMeshComponent->AttachTo(RootComponent);
more ▼

answered Mar 29 '14 at 07:03 PM

avatar image

Dieselhead
1.2k 27 22 211

avatar image Gebba Mar 30 '14 at 01:02 PM

Ah, that makes perfect sense actually facepalm thank you!

avatar image vgambit Sep 22 '14 at 05:47 AM

This will not work unless you call it before you start operating on the component you're attaching.

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

Did you set the Static Mesh Component as the Root Component?

 RootComponent = PickupMeshComponent;

You can then set other components to the root as usual

more ▼

answered May 17 '15 at 06:59 PM

avatar image

8-lines
6 2 3

(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