actor = None just for a fraction of a second.

Discussions about Coding and Scripting

actor = None just for a fraction of a second.

Postby PrinceOfFunky » Thu Apr 13, 2017 3:47 pm

Hello, I have a function which spawns an Actor, logs inside the function show the actor was successfully spawned, out of the function, right after I called it, I log the actor to see if it's None, and it is None indeed, then in the Tick() function, right after the previous log showed me the actor is None, a log shows me the actor is not None, and it's the same reference of when it was spawned.
That's the code:
MainClass:
Code: Select all
function outer(OtherClass anActor) {
   anActor.inner();
   Log(anActor.SpawnedActor); // GIVES None.
}


OtherClass:
Code: Select all
var SomeActor SpawnedActor;

function inner() {
   SpawnedActor = Spawn(class'SomeActor');
   Log(SpawnedActor); // GIVES 'SomeActor0'.
}

function Tick(float Delta) {
   Log(SpawnedActor); // ALWAYS GIVES 'SomeActor0'.
}


Notice the 3 logs, the one that gives None is in the middle between the two that give 'SomeActor0'. How is it possible? Can an offset link, link to a wrong offset for a fraction of a second?
Image
User avatar
PrinceOfFunky
Godlike
 
Posts: 1035
Joined: Mon Aug 31, 2015 10:31 pm

Re: actor = None just for a fraction of a second.

Postby Higor » Thu Apr 13, 2017 4:32 pm

Don't define variables with existing 'field' names (variables, functions, states).
Higor
Godlike
 
Posts: 1743
Joined: Sun Mar 04, 2012 6:47 pm

Re: actor = None just for a fraction of a second.

Postby PrinceOfFunky » Thu Apr 13, 2017 5:54 pm

Higor wrote:Don't define variables with existing 'field' names (variables, functions, states).

Ok well I should admit my variable isn't called "SpawnedActor" but "OIP", how can I know if the name "OIP" has been used in a superclass? (If that's what you're meaning)

EDIT: Ok I just found out something, I think it's cause of concurrency, I made the code like this:
Code: Select all
log1;
call;
log3;


In the called function:
Code: Select all
spawn;
log2;


But the logs come out like this:
log1 - None
log3 - None
log2 - Reference

Is it cause of concurrency so?

EDIT 2: The class with the called function, actually has Tick() which call that function too, this must be the problem!

EDIT 3: I commented the call from within Tick(), now it comes out like log1, log2, log3, all three showing None, how can I know why Spawn() failed?
Last edited by PrinceOfFunky on Thu Apr 13, 2017 6:15 pm, edited 3 times in total.
Image
User avatar
PrinceOfFunky
Godlike
 
Posts: 1035
Joined: Mon Aug 31, 2015 10:31 pm

Re: actor = None just for a fraction of a second.

Postby Chris » Thu Apr 13, 2017 6:09 pm

What Higor is telling you is not to use the same name for Functions, States and variables (those are all UFields..).
You're using the name "outer" for a function.. there is already a very special Object variable with this name in every object..
Chris
Experienced
 
Posts: 116
Joined: Mon Nov 24, 2014 9:27 am

Re: actor = None just for a fraction of a second.

Postby PrinceOfFunky » Thu Apr 13, 2017 6:10 pm

Chris wrote:What Higor is telling you is not to use the same name for Functions, States and variables (those are all UFields..).
You're using the name "outer" for a function.. there is already a very special Object variable with this name in every object..

Next time I won't change names just to show it as an example, I wanted to make it easy for you to understand the code flow, but the names are not those I showed you. I edited the prev post right when you were posting this one .o.

PrinceOfFunky wrote:I commented the call from within Tick(), now it comes out like log1, log2, log3, all three showing None, how can I know why Spawn() failed?


EDIT: SOLVED! I knew I would have regret of it when I decided to do it that way, the situation was like this actually, there are 3 classes:
Class 1:
Code: Select all
spawn class2 with Owner = None;
call class2.outer();
set the class2 Owner;

Class 2 - function outer():
Code: Select all
log1;
call class3.inner();
log3;

Class 3 - function inner():
Code: Select all
if (class2's Owner != None) {spawn OIP;}
log2;


OIP is not spawned cause class2's Owner is None, that's why OIP was not None in the logs from within Tick().
Well it is solved! Thanks everyone for your support :D
Moral: Sometimes you think the problem is inside the box, when it is actually outside lol.
Image
User avatar
PrinceOfFunky
Godlike
 
Posts: 1035
Joined: Mon Aug 31, 2015 10:31 pm


Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 3 guests