Need input from you guys. Simple snake game.

Hello!

I’m a complete UE4 beginner so I thought I would start off making a simple game. In this case a snake game.

I have made a blueprint for the snake that controls the movement and steering.

Is this the right thing to do? To have the logic in the snake itself? Or should i have the logic in the level blueprint instead?

Anyhow, it works and i can control the snakes head with the keyboard.

My problem is how I can create the tail.

I’m thinking:

  1. On Event Begin Play do a for-loop of the amount of tail blocks and create them from a mesh
  2. Store the coordinates of the head block in an array every “Event Tick”.
  3. Do a for-loop of the amount of tail blocks and change these locations with data from the array

Is this a good way to go about this?

Do I have all this logic in the snake blueprint or in the level blueprint?

Any input is much appreciated.

Thanks,

EDIT:

I forgot to say that i’m having problems with step 2.
I cannot find a way to get the objects i create in step 1.
I use Get static mesh to create the tail.

I would keep the logic specific to the snake, in the snake itself. Probably all the stuff to add links to the tail in the Head.

In the level blueprint I would have the scoring logic.

Thanks for the input. That sounds like a good way to think.

I create 10 mesh objects with “Get Static Mesh” with a for-loop in my blueprint.

How can I find them and modify their positions during gameplay?

Is it possible to give them an ID when I create them so I can find/get them later on?

Or is there any other solution to this?

You can assign their reference right after you spawn them to a variable somewhere, probably in an array of them. Or, you can search all actors of it’s type, then check the tag. The Tag is what you are looking for to give it an Id or name.

Making it a Blueprint will make it a little simpler.

I finally got this to work. I made a tail blueprint, spawned it and selected them by class type.

Thanks for the help!!!