Announcement

Collapse
No announcement yet.

Get Static Mesh Bounds (Size)

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

    Get Static Mesh Bounds (Size)

    I know that there is a lovely function that you can use to get the bounds of an actor as long as you have an instance of it, but what if I wanted to get the bounds of a static mesh before I added it? How would I go about that?

    Thanks,
    - Alex.

    #2
    Deep in the recesses of the mind lies everything you have seen in the last minute. To access that information, you would have to know where in your mind it is.

    Yes... I've seen Inside Out. It's a good movie.

    What you can do is spawn the static mesh into the game world, visibility off, in some remote place far, far away and still get its size. Then destroy it. All in a fraction of a second. It only has to exist as long as needed to get its size and whatever other information you want to gather from it. Unless its some insanely huge thing, I doubt you would even know it happened since it is invisible and fast.

    That's one way you could go about it...

    Comment


      #3
      Originally posted by Yggdrasil View Post
      Deep in the recesses of the mind lies everything you have seen in the last minute. To access that information, you would have to know where in your mind it is.

      Yes... I've seen Inside Out. It's a good movie.

      What you can do is spawn the static mesh into the game world, visibility off, in some remote place far, far away and still get its size. Then destroy it. All in a fraction of a second. It only has to exist as long as needed to get its size and whatever other information you want to gather from it. Unless its some insanely huge thing, I doubt you would even know it happened since it is invisible and fast.

      That's one way you could go about it...
      I did think about doing that, but I mean... it's not really a nice way to go about it is it? xD It is a one time thing though, so it wouldn't be so bad. I am doing this in the construction script, though.

      Comment


        #4
        I know that there is a lovely function that you can use to get the bounds of an actor as long as you have an instance of it, but what if I wanted to get the bounds of a static mesh before I added it? How would I go about that?
        Im curious,. In which use case would that make sense?
        Really, this has been asked before by some people and I still cant see a usefull scenario for that where you need to know sizes beforehand....

        Comment


          #5
          I'm generating a room in construction script. I need to be able to place walls on all four sides and then a roof on the top. It is possible if I had each room have it's own width, height and length variables that I could probably go by them to place everything, but even so I've needed this in the past for other things, so it would be useful to have.

          Comment


            #6
            I once made something like this and what I did was:
            I spawned the floor, retrieved its size. Then spawned a wall (still at the BP origin), retrieved the size of the wall and moved it accordingly.
            Then I spawned a roof, got its size and moved it in place...

            A bit simmilar what i do here (especially the stairs): https://forums.unrealengine.com/show...433#post323433
            If you dont scale things its the flow as if "NativeDims" would be always true....

            So its no problem of using the size after you create the mesh. Knowing beforehand is really not neccessary...

            Comment


              #7
              I've also needed to get the size of a static mesh when doing some procedural layout. As far as I could tell, this isn't exposed to Blueprint. In the C++ you would use Mesh->GetBounds().GetBox().GetSize() assuming Mesh is a UStaticMesh. Fortunately, it's not that complicated to create a Blueprint callable function that does this for you. Here is the relevant code snippet for you:

              In YourGameBlueprintLibrary.h:

              Code:
              UCLASS(MinimalAPI)
              class UYourGameBlueprintLibrary: public UBlueprintFunctionLibrary
              {
                  GENERATED_BODY()
              
              public:
              
                  UFUNCTION(BlueprintPure, Category = "YourGame")
                  static FVector GetStaticMeshSize(class UStaticMesh* Mesh);
              };
              In YourGameBlueprintLibrary.cpp:

              Code:
              FVector UYourGameBlueprintLibrary::GetStaticMeshSize(class UStaticMesh* Mesh)
              {
                if (!Mesh)
                  return FVector::ZeroVector;
              
              
                return Mesh->GetBounds().GetBox().GetSize();
              }
              Hopefully that'll be enough to get you started.

              Comment


                #8
                I've also needed to get the size of a static mesh when doing some procedural layout.
                Im still curious to hear about a use case where this is necessary, (knowing the size before spawing)...

                As far as I could tell, this isn't exposed to Blueprint
                Except for the GetLocalBounds function.....

                Comment


                  #9
                  Originally posted by KVogler View Post
                  Im still curious to hear about a use case where this is necessary, (knowing the size before spawing)...

                  Except for the GetLocalBounds function.....
                  Hmm, I had overlooked StaticMeshComponent's GetLocalBounds function. Not sure how I missed that, but oh well. That's probably the function that Aoredon is looking for. Thank you for pointing that out.

                  As for the use case ... the issue isn't knowing the size before spawning, it's knowing the size without spawning. I see this mostly happening with procedural generation that has optional content. For instance, let's say you have a blueprint that creates a dungeon room and its decorations. The level designer places the blueprint in the world and sets the size of the room. The blueprint takes care of filling the room with tables, torches, and other decorations. Before the blueprint can place a decoration in the room it has to know if it can fit (due to the room's size and other decorations it already spawned). It could randomly pick a decoration, spawn it, get it's size, and then possibly delete it if it doesn't fit. But, it would be better to avoid the spawning if the object isn't going to be used.

                  But, I agree with you, this isn't a typical use case.

                  Comment


                    #10
                    Originally posted by Lee Berger View Post
                    Hmm, I had overlooked StaticMeshComponent's GetLocalBounds function. Not sure how I missed that, but oh well. That's probably the function that Aoredon is looking for. Thank you for pointing that out.

                    As for the use case ... the issue isn't knowing the size before spawning, it's knowing the size without spawning. I see this mostly happening with procedural generation that has optional content. For instance, let's say you have a blueprint that creates a dungeon room and its decorations. The level designer places the blueprint in the world and sets the size of the room. The blueprint takes care of filling the room with tables, torches, and other decorations. Before the blueprint can place a decoration in the room it has to know if it can fit (due to the room's size and other decorations it already spawned). It could randomly pick a decoration, spawn it, get it's size, and then possibly delete it if it doesn't fit. But, it would be better to avoid the spawning if the object isn't going to be used.

                    But, I agree with you, this isn't a typical use case.
                    I don't know. It seems like it takes in an instance when I need to be able to pass the class which is what your C++ solution seems to do. I'll try it out now and get back to you.

                    Comment


                      #11
                      et's say you have a blueprint that creates a dungeon room and its decorations. The level designer places the blueprint in the world and sets the size of the room. The blueprint takes care of filling the room with tables, torches, and other decorations. Before the blueprint can place a decoration in the room it has to know if it can fit (due to the room's size and other decorations it already spawned). It could randomly pick a decoration, spawn it, get it's size, and then possibly delete it if it doesn't fit. But, it would be better to avoid the spawning if the object isn't going to be used.
                      Ok. Valid case. I would solve it this way:

                      Initially I assume that at least one decoration item of all available will fit into the room.
                      So the the room BP adds a static mesh component. This spawns the (empty) component.
                      Then I would set the static mesh property of the component to a decoration item and see if it fits.
                      If it does not, I would try to scale it down (torches can come in different sizes). If that still does not work becase the room is too small or scaling would be too excessive, then try the next one.
                      Only when no decoration item fits, not even by scaling, then I would remove the static mesh component again.

                      So, no matter how many meshes you try out, there is only one component involved.
                      You are not constantly spawning and destroying static mesh components.
                      Only in rooms that remain empty because nothing fits you create and destroy a component "for nothing"..

                      Comment


                        #12
                        Sorry I'm late to get back. I had a lot of issues with Visual Studio which confused me. Turns out there was an issues with the project settings which didn't link the libraries and as such caused compiler errors.

                        Lee, your solution worked perfectly. While it does use C++, your solution essentially required zero effort on my end and allows me to continue using Blueprint. Essentially I can still continue on without using C++. I actually learnt quite a bit and I appreciate you putting the time and effort in to help me out.

                        Thank you.

                        Comment


                          #13
                          I found this post looking for a similar solution. I was able to use "Get Bounding Box" from the Static Mesh attached to BP's InstancedStaticMeshComponent. It has min/max x/y/z

                          Comment

                          Working...
                          X