Trying to spawn a widget on an ai character pawn

Here’s my logic.

I’ve got the widget set up just like my pause menu, which works, and I’m just having trouble getting it to spawn when I’m overlapping with the character and pressing a certain key.

I’m starting to think that I’m going about it the wrong way. Maybe i should stick to controls on the player character. I will scrap and try from a different angle tomorrow.

Hi Phillipjphry,

you want to spawn a widget over or at the location of an pawn actor?
Should it be just on the screen, or should it be like 3D spawned in the world?

I think I’m missing here the add to viewport function for that widget when you create it (when it has it’s own canvas), for the case you’re going the first option mentioned above.

Can you explain a bit more what you are trying to achieve? It’s more then just text that the widget shows?

Regards,

My idea was to have a UMG take input on a non player object so i could have different interactions for the same button when overlapping different NPCs in game. It would be neat to have spawn in game, but i think that wouldn’t work well input wise.

I don’t think that this is the right way to handle it.

But you could “on begin overlap” check with what actor you are overlapping, try to cast if successful, set some kind of enum to “actor 1”, If the cast fails, try to cast to another actor, if successful, set the enum to “actor 2” and so on.
Now on the “E Pressed” you could to what value the enum was set on a switch, if set to actor 1, do this, if set to actor 2, do something different.

Could that work for you?

Regards,

Ooh, i will give that a try. Question though, do loops like that cost a lot of processor power?

It should not be that heavy as you are not executing it every tick but only on begin overlap and maybe on end overlap so that should be fine. How many types of actors do you have?

Another optimized version would be that you have some kind of BaseActor and all actors inherit from this Actor. This base actor would have an Enum in it self but it would be set on those child actors so you would only need to try cast once, cast the overlapBegin actor to your baseActor, when done, get from him the actor Type.

Regards,

Here is what I have now in the first person blueprint. I scrapped the idea of doing all the logic on the NPC. all it does is inherit from the basicAIcharacter class and set it’s enum when it begins.

Still can’t get it to trigger any of those print strings.

Ok, that tells us that your beginOverlap event is not called, otherwise some of string should be printed.

On what is the beginOverlap? On the mesh or some collision sphere?
Can you check if both (actor and pawn) have set the correct collisions/overlaps? You could try to set both OverlapAll on both?

Got it! Thanks! I thought I could use the inherited character capsule for collision, but adding a sphere specifically for collision made it trigger.

Now I’m going to try triggering and attaching the UMG to the viewport.

Here’s the final setup.

I had to remember to add a set input game only in the detach from character BP. I’m not sure why, but when I tried and IsValid on the enum switch result, while using the widget as the target object, it wouldn’t fire. I guess I’ll just have widgets building up for now. Bug to be fixed for sure.

On what are you doing IsValid check? On a variable that the Widget is assigned to? That should work. Can you send a picture?

That was it! I was calling the isValid on the return of the enum switch, rather than the get for the widget variable.

Thanks!