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"

How can I respawn a mesh if an item is dropped?

Hi everyone,

I'm currently working on implementing an item system and am trying to figure out how to implement spawning/despawning meshes when dropping and picking up items. I've seen a few examples where an actor's UStaticMeshComponent is destroyed on pickup, but how would I go about respawning that mesh when the item is dropped? Any tips are helpful at this point.

Product Version: Not Selected
Tags:
more ▼

asked May 30 '14 at 01:30 AM in C++ Programming

avatar image

eddyluten
96 5 4 13

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

2 answers: sort voted first

I didn't feel okay with destroying the mesh just for hiding/showing purposes, so I implemented it in the following way (I don't know if this is the "right" way of doing it). I don't have access to my code at the moment, but this is the general gist of it.

  1. On AActor::PostInitializeComponents, I store a reference to my UStaticMeshComponent's StaticMesh member in a private UStaticMesh* variable.

  2. On pickup (called on an overlap event), I call UStaticMeshComponent::SetStaticMesh with a nullptr as its argument so the mesh will no longer be displayed. At this point, I also disable my collision detection and add the item to the player's inventory.

  3. On drop, I call UStaticMeshComponent::SetStaticMesh again, this time providing my private UStaticMesh* variable as its argument. This will display the mesh again and I turn my collision detection on again. When dropping, I update the item's location to be the player's location + FVector(100, 0, 0) and apply a little impulse to simulate a throwing/dropping action.

I'll see if I can dig up a concrete example for this later, but this is the general way I handled it.

more ▼

answered May 30 '14 at 06:00 PM

avatar image

eddyluten
96 5 4 13

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

Add it again i guess :) You name from component decleration

 AddComponent(FName("Mesh"), false, FTransform(), NULL);
more ▼

answered May 30 '14 at 02:22 AM

avatar image

Shadowriver
37.3k 936 172 1116

(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