I created a maze generator and I'm currently trying to figure out how to use an InstancedStaticMeshs in c++. Currently it spawns blueprints extended from a StaticMeshActor and I can only get about 10201 static meshes blueprints before i hit some heavy performance decrease, this is just on a maze alone So when trying to make a rougelike maze dungeon with rooms and floors there are about ten to twenty times the static meshes. That's allot of static mesh blueprints. Anyone have example usage ?
asked Apr 03 '14 at 1:58 AM SaxonRah |
Instanced Static MeshYou can make a new class, InstancedStaticMeshActor and add a Instanced Static Mesh Component Then you spawn that actor and to add additional instances you use this function in the Instanced Static Mesh Component Class
That's pretty much all you need to do! Here's my code from the beta, that I used for my own tests, here's a pic of my tests In my case I extended a regular SMA so I would see the actor when it spawned :) Spawning
.h
.cpp
answered Apr 03 '14 at 8:24 PM Rama SaxonRah Apr 03 '14 at 10:51 PM
Thanks mate! You are the best :) ! oOo.DanBO.oOo May 11 '14 at 6:51 PM
i have a few problems when i try this solution. my objects get spawned in the world. but it seems they dont have a material applied even if i apply it in the code. so for me the main difference is that instead of TSubobjectPtr MyBlock; i use this: TSubobjectPtr MyBlock; and of course also in cpp for the pcip createabstractdefaul..... but then the block has no material :< Rama May 13 '14 at 7:32 AM
you'll have to post your code for us to help you also, it'd be better to post your issue as a separate topic so we can focus just on your issue :) :) Rama Neil.Griffiths Jul 01 '14 at 12:15 AM
I know I'm late to this party but I'm guessing this is because your material isn't set up to work on Instanced Meshes. Open up your material in the Material Editor (by double-clicking it in the Resource Browser) and set the property. :) DJ_Lectr0 Aug 05 '14 at 10:58 PM
What if I needed to apply an instanced Material with a parameter wich is different for every instance? Would I just override AddInstance? And how would I get the static mesh created in there? DJ_Lectr0 Aug 06 '14 at 12:06 AM
And also: How can I enable collision with my character?? Hyperloop Aug 23 '14 at 2:10 AM
Rama, first off, thanks for being so active and helpful in the community I swear every third post I find turns out to be from you :D I'm trying to solve this exact problem for myself as well and I have two quick(ish) questions:
2: If I place multiple instances of this actor into the world, do they each reference the SAME mesh, thereby helping to limit draw calls? That's the other huge issue I am hitting as I try to solve this with blueprints: Each instance of a BP that contains an instanced mesh isn't inheriting or 'grouping'/batching with the other instances even though it's the same mesh. Functionally, that means I can't make use of instanced meshes unless they ALL spawn from the same blueprint....and if they all spawn in the same BP, I can't get a reference to a single instance to destroy it so it's kind of useless for what I need to do :/ Your reply here was the closest thing I have found that might be a solution, I'm not a coder (yet) so I wanted to ask those Questions before I dive in and learn how to implement this :D Hyperloop Aug 23 '14 at 6:43 AM
Editing my post in regards to the first question: it would seem that in 4.4 they have JUST added the ability to do this! "InstancedStaticMeshComponents now set the FHitResult.Item property with the index an instance hit by a collision event. This can be used with the above functions to remove a specific instance and replace it with a real StaticMeshComponent to provide interactivity with Foliage or other behavior." This is great news! Still not sure how/if multiple Blueprints can have objects that are references to the same static mesh. Plorax Oct 08 '14 at 5:19 AM
What is an SMA ? Sorry, I'm not familiar with the acronyms. Also, is this code still valid for UE 4.4 ? Please can someone point me in the right direction or show me a sample project doing the same InstanceStaticMesh thingy.. SaxonRah Oct 08 '14 at 6:21 AM
SMA is StaticMeshActor. I haven't updated this project to 4.4 so im not entirely sure,but it should. Are you making sure you are adding an instance of it ? PhoenixFalcon Nov 22 '15 at 7:59 PM
Hi, I am trying to add InstancedStaticMeshComponent using the code above. It works for single component. However when I try to add three different instanced mesh componentes they all look the same. For example the first added mesh is floor, the second and the third are cubes. Everything is rendered as floor mesh. PhoenixFalcon Nov 29 '15 at 7:44 PM Newest
Turns out the problem is with this line static ConstructorHelpers::FObjectFinder StaticMeshOb_torus(TEXT("StaticMesh'/Engine/EngineMeshes/Cube.Cube'")); I removed static and it seems to be working. |
I created a maze generator and I'm currently trying to figure out how to use an InstancedStaticMeshs in c++. Currently it spawns blueprints extended from a StaticMeshActor and I can only get about 10201 static meshes blueprints before i hit some heavy performance decrease, this is just on a maze alone So when trying to make a rougelike maze dungeon with rooms and floors there are about ten to twenty times the static meshes. That's allot of static mesh blueprints. Anyone have example usage ?
asked Apr 03 '14 at 1:58 AM SaxonRah Dieselhead Apr 03 '14 at 9:43 PM
I'm only guessing here but I think a game like this would also benefit greatly from level streaming. SaxonRah Apr 03 '14 at 10:51 PM
How would you level stream from actors spawned at run time ? Dieselhead Apr 04 '14 at 2:04 AM
Well thats what you get when browsing this place the last hour of work :) Sorry, carry on! |
Instanced Static MeshYou can make a new class, InstancedStaticMeshActor and add a Instanced Static Mesh Component Then you spawn that actor and to add additional instances you use this function in the Instanced Static Mesh Component Class
That's pretty much all you need to do! Here's my code from the beta, that I used for my own tests, here's a pic of my tests In my case I extended a regular SMA so I would see the actor when it spawned :) Spawning
.h
.cpp
answered Apr 03 '14 at 8:24 PM Rama SaxonRah Apr 03 '14 at 10:51 PM
Thanks mate! You are the best :) ! oOo.DanBO.oOo May 11 '14 at 6:51 PM
i have a few problems when i try this solution. my objects get spawned in the world. but it seems they dont have a material applied even if i apply it in the code. so for me the main difference is that instead of TSubobjectPtr MyBlock; i use this: TSubobjectPtr MyBlock; and of course also in cpp for the pcip createabstractdefaul..... but then the block has no material :< Rama May 13 '14 at 7:32 AM
you'll have to post your code for us to help you also, it'd be better to post your issue as a separate topic so we can focus just on your issue :) :) Rama Neil.Griffiths Jul 01 '14 at 12:15 AM
I know I'm late to this party but I'm guessing this is because your material isn't set up to work on Instanced Meshes. Open up your material in the Material Editor (by double-clicking it in the Resource Browser) and set the property. :) DJ_Lectr0 Aug 05 '14 at 10:58 PM
What if I needed to apply an instanced Material with a parameter wich is different for every instance? Would I just override AddInstance? And how would I get the static mesh created in there? DJ_Lectr0 Aug 06 '14 at 12:06 AM
And also: How can I enable collision with my character?? Hyperloop Aug 23 '14 at 2:10 AM
Rama, first off, thanks for being so active and helpful in the community I swear every third post I find turns out to be from you :D I'm trying to solve this exact problem for myself as well and I have two quick(ish) questions:
2: If I place multiple instances of this actor into the world, do they each reference the SAME mesh, thereby helping to limit draw calls? That's the other huge issue I am hitting as I try to solve this with blueprints: Each instance of a BP that contains an instanced mesh isn't inheriting or 'grouping'/batching with the other instances even though it's the same mesh. Functionally, that means I can't make use of instanced meshes unless they ALL spawn from the same blueprint....and if they all spawn in the same BP, I can't get a reference to a single instance to destroy it so it's kind of useless for what I need to do :/ Your reply here was the closest thing I have found that might be a solution, I'm not a coder (yet) so I wanted to ask those Questions before I dive in and learn how to implement this :D Hyperloop Aug 23 '14 at 6:43 AM
Editing my post in regards to the first question: it would seem that in 4.4 they have JUST added the ability to do this! "InstancedStaticMeshComponents now set the FHitResult.Item property with the index an instance hit by a collision event. This can be used with the above functions to remove a specific instance and replace it with a real StaticMeshComponent to provide interactivity with Foliage or other behavior." This is great news! Still not sure how/if multiple Blueprints can have objects that are references to the same static mesh. Plorax Oct 08 '14 at 5:19 AM
What is an SMA ? Sorry, I'm not familiar with the acronyms. Also, is this code still valid for UE 4.4 ? Please can someone point me in the right direction or show me a sample project doing the same InstanceStaticMesh thingy.. SaxonRah Oct 08 '14 at 6:21 AM
SMA is StaticMeshActor. I haven't updated this project to 4.4 so im not entirely sure,but it should. Are you making sure you are adding an instance of it ? PhoenixFalcon Nov 22 '15 at 7:59 PM
Hi, I am trying to add InstancedStaticMeshComponent using the code above. It works for single component. However when I try to add three different instanced mesh componentes they all look the same. For example the first added mesh is floor, the second and the third are cubes. Everything is rendered as floor mesh. PhoenixFalcon Nov 29 '15 at 7:44 PM Newest
Turns out the problem is with this line static ConstructorHelpers::FObjectFinder StaticMeshOb_torus(TEXT("StaticMesh'/Engine/EngineMeshes/Cube.Cube'")); I removed static and it seems to be working. |
I'm only guessing here but I think a game like this would also benefit greatly from level streaming.
How would you level stream from actors spawned at run time ?
Well thats what you get when browsing this place the last hour of work :)
Sorry, carry on!