Accessing Undefined Variables

Hello! I’m very new to Unreal Engine with only a little bit of knowledge. And I may have bit off more than I could chew. Essentially the issue is, from a player controller, which runs everything, I need to access an udefined variable. I came from Roblox Studio, which had a nifty function called waitforchild if anyone is familiar with that. It allows you to wait for an undefined asset to load. In my case that “asset” is a variable, and several static meshes of my character.

More detailed description:
Gamemode blueprint loads the character. Character is possessed. Player controller can’t access the variables or the hull, turret, and cannon, in my tank. My conclusion is that the issue is because the player controller doesn’t yet know what I’m going to spawn, and therefore won’t let me rotate the tank even once it spawns.

Things I’ve tried:
I have tried to set up all the variables in my player controller for each individual tank, but once it spawns, I still can’t access the static mesh components.
I’ve tried to spawn the tank from the player controller. But I still run into the issue that if I swap tanks, it won’t know what the components are.

Thanks in advance!

1 Like

When you spawn a tank, you get a reference. That reference will give you access to everything.

I’d do it the other way around; rather than having the player wait for the tank to spawn, I’d have the tank send a message to the player when it spawns. So the flow would be:

  • Player spawns. It has a (null) reference to its tank.
  • The player’s tank spawns. It gets a reference to the player and then calls a function on the player to essentially say “This tank is yours”
  • The player now has a reference to the tank, and can do whatever additional setup it needed to do.

This does mean you’d have to have null checks practically everywhere, but you generally need those for this kind of dynamic spawning anyway.

All right, let me try to program it in.

The only issue is that the Gamemode base spawns the character, I don’t know how to transmit information across two scripts. Especially Gamemode base and the player controller. I’m not entirely sure how they replicate across clients.

You can use ‘get actor of class’ to get a reference to something in the level.

Let me post a few screenshots.

This is in the gamemode base. Look right to you?

This is the reference

image

But a game mode will spawn what you what anyway, you don’t have to put code in it

image

1 Like

How would I go about sending it to the Player controller? Sorry, I’m probably bothering you.

I am aware. I just need to be able to dynamically spawn different tanks with different stats.

I’m probably not the right person to ask about this, as I never put code in either of these places :slight_smile: Especially if it’s multiplayer.

Hm, how would you go about doing this kind of thing? I’m extremely new with barely any experience, I’m just trying to come up with solutions since no one has tutorials about this.

I would just make a ‘tank manager’ blueprint and drop it in the level.

Then you can just make it work anyway you want.

1 Like

I’ll give it a try. Can you elaborate a little further on that please?

What’s it supposed to do?

So have you ever played a game like World of Tanks or War Thunder? Oh boy, can’t reply anymore. First day maximum I guess.

Edit 1:
So you can pick out different tanks. And then each has unique stats. Such as rotating speed, forward and backward speed. Health, armor, etc.

I want to be able to pick out a different tank currently just in the editor but something simple, that way I can make tank selecting and tank blueprint creation easier.

Edit 2:
I have to go for a bit, but I’ll be back on, rest assured I’ll try to implement some of your ideas. Thanks again @ClockworkOcean.

1 Like

Nope :slight_smile:

Edit it in here…

1 Like