Announcement

Collapse
No announcement yet.

Is it possible - Play mode add to scene

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

    Is it possible - Play mode add to scene

    Is it possible to add assets into a scene when in play mode.
    I mean when I play and get the need to add an asset near my location. I hit the 'F' key for example and it place a cube there. When I stop the game the cube is still there as an asset.
    How would you blueprint that?

    #2
    Hello,
    You can use "spawn actor from class" to add an actor into a scene. You can "set" a component or a child actor too.

    Comment


      #3
      Originally posted by Fen View Post
      Hello,
      You can use "spawn actor from class" to add an actor into a scene. You can "set" a component or a child actor too.
      Yes but as soon as you end the game this actor is gone.

      Comment


        #4
        You can't unfortunately (not via blueprints anyway).

        A function that spawns an actor in both editor and game world sounds like a useful function to have though.

        I will try to make a C++ function for this when I have time.

        4.10 Update! -> [Community Project] WIP Weather & Ocean Water Shader
        WIP Interactive Water Shader, WIP 2D Water Sim
        WIP FFT Ocean w/ Foam, Quad-tree Infinite Ocean LOD

        Comment


          #5
          Originally posted by TK-Master View Post
          You can't unfortunately (not via blueprints anyway).

          A function that spawns an actor in both editor and game world sounds like a useful function to have though.

          I will try to make a C++ function for this when I have time.
          Thanks I would appreciate that.
          My thought on this was that we could make our projects evolve with this functionality. I mean you start with the tools you're given and end with you building your game entirely in the game while it plays. I love the idea of building my own tools to speed up the development process the more I work with it.

          Comment


            #6
            That would be pretty handy actually. There is the "save changes" during runtime ability when you press the "K" key, which I have had mixed results with, but it will also only save changes to existing items, not newly spawned 1s

            Comment


              #7
              I'm not sure if this still works, but you used to be able to spawn objects at runtime, select them in the outliner, copy them and then stop the game. Then you could paste them back in. Does this still work?
              iTween For UE4
              Procedural pathed animation for actors, components & UMG - $0
              Runtime DataTable
              DataTables dynamically loaded from text or Google Sheets while your game is running!
              easyCSV
              Fast, cheap, and accurate CSV parsing at runtime!

              Comment


                #8
                Oh, i didn't understand at first read, sorry. I wonder if you could use an instance to save added elements in an array or struct and save this on quit, then use the savegame file to extract added infos. Only an idea on the fly.

                Comment


                  #9
                  Originally posted by Fen View Post
                  Oh, i didn't understand at first read, sorry. I wonder if you could use an instance to save added elements in an array or struct and save this on quit, then use the savegame file to extract added infos. Only an idea on the fly.
                  No worries mate,
                  I have not looked into the save functionality yet but if I would be designing it I wouldn't do read and write as a binary format but instead use XML. This way anyone could parse the file and work with the data to build new innovative functions.

                  Comment


                    #10
                    You can use the savegame method to save objects then re-spawn them on BeginPlay but you are still not going to get the spawned object into the "editor world".

                    4.10 Update! -> [Community Project] WIP Weather & Ocean Water Shader
                    WIP Interactive Water Shader, WIP 2D Water Sim
                    WIP FFT Ocean w/ Foam, Quad-tree Infinite Ocean LOD

                    Comment


                      #11
                      So.. I was able to make a simple C++ function that can spawn at runtime an object in the editor instead of the game world.

                      .h
                      Code:
                      	UFUNCTION(BlueprintCallable, Category = "Game", Meta = (FriendlyName = "Spawn Actor from Class in Editor"))
                      	static void SpawnActorInEditor(UClass* Class, FTransform SpawnTransform, AActor* &Result);
                      .cpp
                      Code:
                      #include "UnrealEd.h"
                      
                      void UMyFunctionLibrary::SpawnActorInEditor(UClass* Class, FTransform SpawnTransform, AActor* &Result)
                      {
                      	if (Class && GEditor)
                      	{
                      		Result = GEditor->AddActor(GEditor->LevelViewportClients[0]->GetWorld()->GetLevel(0), Class, SpawnTransform);
                      	}
                      }
                      In your Build.cs you will need to add "UnrealEd" in the PublicDependencyModuleNames.

                      (Let me know if you don't know your way around C++ and I will try to help)

                      Click image for larger version

Name:	spawnInEditor.jpg
Views:	1
Size:	28.4 KB
ID:	1076182

                      This will spawn the object in the editor only (not visible at runtime) so you can combine this with the default SpawnActorFromClass node if you need to see what you are spawning in game

                      It's not perfect though and it has it's limitations.. it doesn't expose any "Expose on Spawn" variables when you select the class for example (like the SpawnActorFromClass does).
                      Last edited by TK-Master; 05-11-2015, 07:44 PM. Reason: Added returned actor "Result" to the function..

                      4.10 Update! -> [Community Project] WIP Weather & Ocean Water Shader
                      WIP Interactive Water Shader, WIP 2D Water Sim
                      WIP FFT Ocean w/ Foam, Quad-tree Infinite Ocean LOD

                      Comment


                        #12
                        That is quite simple! Would be good to see how far we can push this kind of thing to allow full in game level editors essentially.

                        Comment


                          #13
                          Yup! there is tons of potential with this (kinda surprised this was not done already )

                          4.10 Update! -> [Community Project] WIP Weather & Ocean Water Shader
                          WIP Interactive Water Shader, WIP 2D Water Sim
                          WIP FFT Ocean w/ Foam, Quad-tree Infinite Ocean LOD

                          Comment

                          Working...
                          X