SimCity like building placement

Hey guys, I have a question. I wanna make a game like SimCity. I already done this that when I click on something with the mouse cursor, it will spawn my actor there (a building). But when I moe my mouse, I want the not placed building to move with my cursor, so I already done that with an Loop, which spawns the actor at mouse position, wait 0.2 secs, and destroy the actor again. Thats kinda looking to that, what I want, but this 0.2 seconds cause flickering. Do you know any possibility to solve my problem without that 0.2 secs delay? I mean when I put out the 0.2 secs delay, It will spawn and immediatly destroy the actor, so I don’t even see the actor. I need a actor which follows the mouse without flickering. Thats all. Thanks :wink:

You should code/BP it like this:

on click: spawn an actor at your mouse location
every tick: set actors location and rotation based on mouse input and desired functionality.
(tick is basicly unreals main ‘delay loop’ - except the delay on each looping is determined by many factors such as FPS)

The reason your getting flickering is because you are spawning and destroying - it is much better to spawn once and then set the location every tick, this will solve your flicker problem.

Actors have many properties (variables) that can be accessed and changed through either blueprints or code.

Well, I don’t know why I just hadn’t this idea with just set the position. Many many thanks :smiley:

Well im a c++ coder rather than a blueprint maker, so im not sure what the issue will be with your blue print -

in code I would look at the part of character that handles ‘destruction’ - that is what occurs when that class is no longer in use, in there Id be sure to add code that will remove the memory allocation for the spawned actor on characters destruction. Ill have to hand the blueprint specifics of that to the comunity tho you may want to look at making your spawned actor a ‘sub component’ of your character as subcomponents should be destroyed gracefully.

Ok, I hope somebody will help me. By the way, is this error important or can I ignore this for a while till i have a solution.

I’m now on C++ so can you please say how I can remove the error?

Ok so now it works so far, but If i play it in Editor and hit ESC, it says “Error / Warnings reportet…”. In the log it says “Accessed None ‘CallFunc_FinishSpawningActor_ReturnValue’ from node Construction Script in blueprint MyCharacter”. Whats that?

Sory for the delay in answering - ive been moving house. Sory to hear this problem is still unresolved.

Ill see if I can help you more,

Looking at the reported error message it would seem it is still a blue print error. specificaly in the ‘mycharacter blueprint’. Assuming you have created a blue print from your c++ class of course the error could be in the c++ code too.

It would seem by the error that you are spawning actors in the constructor of your my character class. According to the documentation this is an unsafe operation (ie may cause errors). It is recomended to do the spawning in begin play or on some input event that will be called after begin play.

Try structuring your code like this: (pseudo code)

constructior
{
set up variables/structs for objects that will be spawned.
}

begin play
{
instanciate any internal objects needed during play.
}

setupplayerinputcomponent
{
define function for mouse clicks
}

leftmousepressed
{
upon conditions you want to
{
spawn ‘building’ actor.
set building spawned bool = true;
}
}

tick
{
if building spawned bool = true
{
get mouse location
set building actors location
}
}

If youre still getting errors post up your code and Ill have a look.

Oh and the question of can you ignore errors - best practice is to never ignore errors because everythign you make from there on may have flaws that you dont know about.