Announcement

Collapse
No announcement yet.

[FEATURE REQUEST] Construction script for BP components

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

    #16
    Did you try using "Add Child Actor Component"?

    Edit:

    Actually, I dont quite understand why you would want to use a construction script inside components to provide functionality. This is in my opinion the wrong approach. I agree with the above statement to use methods to add static mesh components to an existing actor.
    Also, instead of spawning actors you will want to add them as child actors through the "Add Child Actor Component" Node. You will not be able to pass anything to the "Exposed on Spawn" Variables of the child actor, so its construction script will run with the default parameters. But you receive a pointer to this child through the above mentioned node and you can set its exposed variables afterward. After setting them, you will want to rerun the construction script. This currently seems to be not supported by the engine (that is: manually rerunning the construction script) but it is possible through C++ afaik. I have already tried it today, when I had to leave in a rush and it basically worked for except one problem. I will try to fix it next week though, after I have consulted the community about what I am trying to do xD

    Edit2: Please correct me if I am off or wrong with anything I point out or when you have something to point out, dont keep it to yourself Im still new to unreal engine (I started a few months ago)
    Last edited by rYuxq; 04-08-2016, 04:07 PM.

    Comment


      #17
      Also, instead of spawning actors you will want to add them as child actors through the "Add Child Actor Component" Node. You will not be able to pass anything to the "Exposed on Spawn" Variables of the child actor, so its construction script will run with the default parameters. But you receive a pointer to this child through the above mentioned node and you can set its exposed variables afterward. After setting them, you will want to rerun the construction script. This currently seems to be not supported by the engine (that is: manually rerunning the construction script) but it is possible through C++ afaik. I have already tried it today, when I had to leave in a rush and it basically worked for except one problem. I will try to fix it next week though, after I have consulted the community about what I am trying to do xD
      In the end they are supposed to be independent actors.
      Id like to split functionality on the actor level. A house BP knows how to build a house from modular meshes and given parameters about story count, roof type, etc.
      Now I want a cityblock BP that places those house actors in a fashion so they form a pattern, again driven by parameters.
      The City BP would then place a couple of cityblocks, together, set their values, to form a city.
      Then I can still go into each placed house or cityblock and tweak the actor values individually.
      Rerunning the construction script would indeed be required after a value change. So for a house BP, the script would need to rerun either when I change a value in the details panel, or change a value in the cityblock BP (holding a reference to the house BP), which is then supposed to rebuild the house(s).

      I just want to avoid constructing a city with houndrets of (more or less individual) houses in one huge levelscript or something, because if i change just one value on one of the meshes, the whole city would be rebuilt.

      Comment


        #18
        That is exactly what I am doing as well and it works. Last time, I had some troubles reading the values of the child BP actor afterwards, but I think that was due to me reading the value before I had reconstructed it (and thus the value was just the default value of 0). When I read the value after reconstruction in the very same Blueprint, it was the way I expected it.

        What I am doing is the following (you will need a C++ project - I hope your project is not just for blueprints):
        1. Create a new C++ class named "MyBlueprintFunctionLibrary" or however you want to call it and inherit from BlueprintFunctionLibrary
        2. The header file looks like this:
        Code:
        // Fill out your copyright notice in the Description page of Project Settings.
        
        #pragma once
        #include "Kismet/BlueprintFunctionLibrary.h"
        #include "MyBlueprintFunctionLibrary.generated.h"
        
        /**
         * 
         */
        UCLASS()
        class MYGAME_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
        {
        	GENERATED_BODY()
        	
        public:
        	UFUNCTION(BlueprintCallable, Category="GlobalFunctionLibrary")
        		static void CallMe(class AActor* actor);
        	
        };
        3. The source file looks like this:
        Code:
        // Fill out your copyright notice in the Description page of Project Settings.
        
        #include "MYGAME.h"
        #include "GameFramework/Actor.h"
        #include "MyBlueprintFunctionLibrary.h"
        
        
        
        void UMyBlueprintFunctionLibrary::CallMe(AActor* actor){
        	actor->RerunConstructionScripts();
        }
        There are other methods available you could call on an actor in order to reconstruct it, but I am not sure what the difference is and which would be the best way. I also wonder why there is no default node to reconstruct a BP, so maybe there is a catch? I am going to post a question about it though, so stay tuned maybe?

        After you hit compile in your editor, you can access this method from anywhere in every blueprint as a node.

        Edit: Be aware of loops. If you call this method inside the construction script of two actors on each other, you will end up causing an infinite loop
        Last edited by rYuxq; 04-09-2016, 05:04 AM.

        Comment


          #19
          This functionality would still be useful, it's an oversight to not implement it.

          I have an actor component that enhances the behaviour of whatever actor it's added to. Unfortunately you can't see the effects of it in the editor until you hit play because it's lacking a construction script. The intent is to simply add it to any actor and it just works, but instead the user now specifically has to call its construction function from within their actor's construction script.

          In my example I can add a skeletal mesh actor to the world and attach my component and during play it works as intended, but if I want it to look right in the editor I now have to add a blueprint specifically for that use case, even though the only thing it does is call a construction function. This is pointless structural bureaucracy.

          This could be done much better. I don't see the reasoning behind NOT having a construction script in a component either by design or by the limitations of the framework. For a publisher it is much easier to simply indicate which component to add to an actor than to also need to show people what blueprints they need to make for it to work. This defies the purpose of components. They should be as self-encapsulated as the developer wants them to be.
          Last edited by Antidamage; 04-19-2018, 12:29 AM.

          Comment


            #20
            Why not just create the meshes as components from within the actor ?

            Though your example with the boxes, these would rather be independent actors.

            so, implement your oop at the actor level, not component.

            Look into the factory design pattern. You can create one instance of a 'factory' bp, that handles all spawing and deleting of a certain type of actor bp

            Comment


              #21
              Oh, and better not use child actors unless you really need to.

              You can attach them instead, and/or keep references in an array

              Comment


                #22
                Didn't see there were 2 pages...

                Looks like what you're really asking for is being able to spawn actors in construction script, at editor time. The first isn't possible, but you can spawn objects in editor by using blutility.

                This is something that's being improved if we look at the roadmap, like datasmith there is a more general scripting support coming to create objects in editor.

                Comment

                Working...
                X