Announcement

Collapse
No announcement yet.

UObject vs Actor event graphs

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

    UObject vs Actor event graphs

    I'm trying to make a skill system that allows skills to have their implementation be defined through blueprint event graphs. Having noticed that blueprints inheriting from UObject can also have event graphs, I decided to make my C++ Skill base class inherit from UObject rather than Actor because Actor has a lot of unnecessary overhead for my purposes. The problem I'm encountering though is that UObject event graphs don't have access to global blueprint functions like GetGameMode or any Blueprint Function Libraries.

    Does anyone know if it is possible to get access to these functions, other from the obvious choice of inheriting from Actor?
    Journeyman's Minimap - Available on Marketplace - Forum topic - Video

    #2
    https://answers.unrealengine.com/que...-in-uobje.html

    Some nodes missing, because UObjects, do not provide world context by default (although they have virtual function GetWorld()).

    It's reported as intended behaviour, although I still disagree with it.
    I should be able to provide custom world context for functions, which require it, and be able to use them from UObject classes inside blueprints.

    Right now to work around this, I have to either rewrite those functions, or wrap them into custom piece of code, which is kind of counter productive.
    https://github.com/iniside/ActionRPGGame - Action RPG Starter kit. Work in Progress. You can use it in whatever way you wish.

    Comment


      #3
      Ah, I figured it had something to do with UObject having no world context so I tried overriding
      Code:
      	virtual class UWorld* GetWorld() const;
      	class UWorld* GetWorldChecked(bool& bSupported) const;
      	bool ImplementsGetWorld() const;
      In my opinion too that should make those functions accessible. Thanks for sharing your knowledge.
      Journeyman's Minimap - Available on Marketplace - Forum topic - Video

      Comment


        #4
        Edit: Deleted outdated findings
        Last edited by Zhi Kang Shao; 06-21-2015, 07:47 PM.
        Journeyman's Minimap - Available on Marketplace - Forum topic - Video

        Comment


          #5
          Okay, actually scratch what I said before. Good news, overriding GetWorld() does give your UObject event graph access to all static functions, like GetGameMode, GetAllActorsOfClass and your own blueprint function libraries (both C++ and BP assets). The only thing you need to make sure is that your implementation does not in some way call the original UObject::GetWorld() method, because when the original method is called, the UObject base class concludes that you haven't overriden GetWorld.

          In my case, I called the original UObject::GetWorld by accident via Outer->GetWorld() where Outer did not have a custom implementation. But now I return a custom UWorld * pointer or simply NULL if its not available and the world context dependent blueprint nodes become available. So there you have it, world context dependent blueprint nodes available in UObject event graphs.

          Click image for larger version

Name:	graphs.png
Views:	1
Size:	42.4 KB
ID:	1080267

          Skill.h:
          Code:
          class MYGAME_API USkill : public UObject
          {
          	GENERATED_BODY()
          
          public:
          	UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category=MyGame)
          	void ExecuteSkill();
          
          	// Begin UObject interface
          	virtual class UWorld* GetWorld() const override;
          	// End UObject interface
          
          	// Set this to a valid world right after creation
          	UPROPERTY(Transient)
          	UWorld * World;
          }
          Skill.cpp:
          Code:
          UWorld* USkill::GetWorld() const
          {
          	return World;
          }
          Edit: image and example code added
          Last edited by Zhi Kang Shao; 06-22-2015, 08:36 AM.
          Journeyman's Minimap - Available on Marketplace - Forum topic - Video

          Comment


            #6
            Thanks for sharing your research NisshokuZK !



            Rama
            100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!

            UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin

            Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama

            Comment


              #7
              You're welcome Rama. I'm glad we can have light weight but powerful event graphs!
              Journeyman's Minimap - Available on Marketplace - Forum topic - Video

              Comment


                #8
                Hi Zhi Kang Shao,

                I've been trying to reproduce what you've done here was there anything else that enabled you to get this working? I'm trying to create UObjects that have access to standard functions and you're the only person that I've found that has had any success with this.

                Thanks!

                Comment

                Working...
                X